Coder Social home page Coder Social logo

facebook / pathpicker Goto Github PK

View Code? Open in Web Editor NEW
5.1K 122.0 281.0 1.41 MB

PathPicker accepts a wide range of input -- output from git commands, grep results, searches -- pretty much anything. After parsing the input, PathPicker presents you with a nice UI to select which files you're interested in. After that you can open them in your favorite editor or execute arbitrary commands.

Home Page: https://facebook.github.io/PathPicker/

License: MIT License

CSS 3.66% HTML 6.05% Python 86.24% Shell 3.49% Ruby 0.56%

pathpicker's Issues

fpp doesn't pass path to command properly for paths in the top dir w/out ./ prefix

The output of ack -l or grep -l that lists as demonstrated below is parsed properly by fpp (the interactive selection works), but when you execute a command on it (for example open the editor) it doesn't pass the proper path.

In the case of the first file listed below, fpp passes the following to vim:

/home/user/www/system-images/android-22/default/x86_64

when the proper path is:

/home/user/**vendor/android/sdk/**system-images/android-22/default/x86_64/source.properties

  1. The CWD is /home/user/vendor/android/sdk/
  2. I have no idea where the www/ is coming from
ack xml -l | head                                                                                                                                                                    130 ↵
system-images/android-22/default/x86_64/source.properties
system-images/android-22/default/x86_64/NOTICE.txt
system-images/android-22/google_apis/x86_64/source.properties
system-images/android-22/google_apis/x86_64/NOTICE.txt
system-images/android-21/default/x86_64/source.properties
system-images/android-21/default/x86_64/NOTICE.txt
system-images/android-21/google_apis/x86/source.properties
system-images/android-21/google_apis/x86/NOTICE.txt
system-images/android-21/google_apis/x86_64/source.properties
system-images/android-21/google_apis/x86_64/NOTICE.txt

Testing multiple version of python.

There's an excellent tox package that can test multiple version of python in one command.
The only requirement is for the user to have the version installed.

Say you have all of this:

python26 -V
python27 -V
python33 -V
python34 -V

You can run one command to automatically test all of it:

tox

I already have it running in my local branch, let me know if you think this is good and I'll create a PR.

I have a directory that breaks fpp

$ ls Music|fpp
Traceback (most recent call last):
File "/home/jackson/src/PathPicker/src/choose.py", line 55, in <module>
curses.wrapper(doProgram)
File "/usr/local/lib/python2.7/curses/wrapper.py", line 43, in wrapper
return func(stdscr, *args, **kwds)
File "/home/jackson/src/PathPicker/src/choose.py", line 26, in doProgram
screen.control()
File "/home/jackson/src/PathPicker/src/screenControl.py", line 266, in control
self.moveCursor()
File "/home/jackson/src/PathPicker/src/screenControl.py", line 498, in moveCursor
self.stdscr.move(y, x)
_curses.error: wmove() returned ERR

I put a pastebin of 'ls Music' here:
http://pastebin.ca/raw/2999325

I can't figure out what it's puking on though, I made another directory with some of the odd characters used and fpp handles that one fine...

Python 3.0 compatibility

I'm on 10.10.3. Ran brew install fpp and then fpp, and got this:

File "/usr/local/Cellar/fpp/0.5.3/libexec/src/processInput.py", line 126
    print USAGE_STR
                  ^
SyntaxError: Missing parentheses in call to 'print'
  File "/usr/local/Cellar/fpp/0.5.3/libexec/src/choose.py", line 54
    print 'Nothing to do!'
                         ^
SyntaxError: Missing parentheses in call to 'print'
sh: /Users/dan/.fbPager.sh: No such file or directory

_curses.error: curs_set() returned ERR

In rxvt-unicode, I hit this every time I try switching to command mode:

Traceback (most recent call last):
  File "PathPicker/src/choose.py", line 58, in <module>
    curses.wrapper(doProgram)
  File "7/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "PathPicker/src/choose.py", line 30, in doProgram
    screen.control()
  File "PathPicker/src/screenControl.py", line 271, in control
    self.processInput(inKey)
  File "PathPicker/src/screenControl.py", line 344, in processInput
    self.beginEnterCommand()
  File "PathPicker/src/screenControl.py", line 434, in beginEnterCommand
    self.helperChrome.output(self.mode)
  File "PathPicker/src/screenControl.py", line 62, in output
    curses.curs_set(BLOCK_CURSOR)
_curses.error: curs_set() returned ERR

The man page seems to indicate that the terminal doesn't support that setting, and it does work fine in xterm.

dotfiles are ignored

for instance if I have
.gitignore
in my git status output. it can't be selected using PathPicker.

Curses error

https://www.technovelty.org/linux/a-short-tour-of-term.html
My terminal is set to xterm-color and I am getting following error

Traceback (most recent call last):
File "/usr/local/Cellar/fpp/0.5.5/libexec/src/choose.py", line 56, in
curses.wrapper(doProgram)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/curses/wrapper.py", line 43, in wrapper
return func(stdscr, _args, *_kwds)
File "/usr/local/Cellar/fpp/0.5.5/libexec/src/choose.py", line 27, in doProgram
screen.control()
File "/usr/local/Cellar/fpp/0.5.5/libexec/src/screenControl.py", line 275, in control
self.printAll()
File "/usr/local/Cellar/fpp/0.5.5/libexec/src/screenControl.py", line 493, in printAll
self.printChrome()
File "/usr/local/Cellar/fpp/0.5.5/libexec/src/screenControl.py", line 503, in printChrome
self.helperChrome.output(self.mode)
File "/usr/local/Cellar/fpp/0.5.5/libexec/src/screenControl.py", line 63, in output
curses.curs_set(INVISIBLE_CURSOR)
_curses.error: curs_set() returned ERR

Having problem running on Linux (Ubuntu 12.04 Precise)

I checked out the repo to: /usr/local/src/PathPicker and created the symlink like this:
root@precisebox:/usr/local/bin# ln -s /usr/local/src/PathPicker/fpp fpp

then when i try running fpp, i see this message:

hmuser@precisebox:~$ which fpp
/usr/local/bin/fpp
hmuser@precisebox:~$ fpp --help
/usr/local/bin/fpp: line 18: cd: /usr/local/bin//usr/local/src/PathPicker: No such file or directory
python2: can't open file '/src/printHelp.py': [Errno 2] No such file or directory

more info:

hmuser@precisebox:~$ readlink /usr/local/bin/fpp
/usr/local/src/PathPicker/fpp
hmuser@precisebox:~$ ls -al /usr/local/bin/fpp
lrwxrwxrwx 1 root root 29 May  7 16:45 /usr/local/bin/fpp -> /usr/local/src/PathPicker/fpp
hmuser@precisebox:~$ ls -al /usr/local/src/PathPicker/
total 60
drwxrwxr-x 5 hmuser hmuser 4096 May  7 16:37 .
drwxr-xr-x 3 root   root   4096 May  7 16:25 ..
drwxrwxr-x 2 hmuser hmuser 4096 May  7 16:24 assets
-rw-rw-r-- 1 hmuser hmuser 1918 May  7 16:24 CONTRIBUTING.md
-rwxrwxr-x 1 hmuser hmuser 1454 May  7 16:24 fpp
-rw-rw-r-- 1 hmuser hmuser  561 May  7 16:24 fpp.rb
drwxrwxr-x 8 hmuser hmuser 4096 May  7 16:24 .git
-rw-rw-r-- 1 hmuser hmuser   89 May  7 16:24 .gitignore
-rw-rw-r-- 1 hmuser hmuser 4502 May  7 16:24 index.html
-rw-rw-r-- 1 hmuser hmuser 1531 May  7 16:24 LICENSE
-rwxrwxr-x 1 hmuser hmuser  347 May  7 16:24 makeDist.sh
-rw-rw-r-- 1 hmuser hmuser 1981 May  7 16:24 PATENTS
-rw-rw-r-- 1 hmuser hmuser 3332 May  7 16:24 README.md
drwxrwxr-x 2 hmuser hmuser 4096 May  7 16:42 src

good thing is, the issue is fixed by changing the commented out line to the line after:

while [ -h "$WHEREAMI" ]; do
  # WHEREAMI=$(dirname "$WHEREAMI")"/"$(readlink "$WHEREAMI")
  WHEREAMI=$(readlink "$WHEREAMI")
done

hopefully this helps.

Bad brew instructions

This:

brew upgrade; brew install fpp; fpp

Should probably be this:

brew update; brew install fpp; fpp

Use Python2 when available

In the two systems I use python is already pointing to 3.x whereas python2 is used as a fallback. I believe it's good to select python2 to run if it's available in the system.

Breaks when not in toplevel Git directory

git status | fpp, selecting files, and applying them to git add works fine when I'm at the top level of a Git repo, but not if I enter a subdirectory. It appears to append the selected file to the git repo path, not pwd.

Offer a pure Python alternative script

I don't know if you are ok with replacing the shell script with a pure Python script, but even if you prefer to have the shell part, at least provide a pure Python version as an alternative.

This way you can us the tool under windows, and for any shell flavor (bash, sh, zsh, shell fish, etc).

In the end, i feel like it would be easier to get rid of the bash part completely though, since you can make a Python code working on any Python version, you can make it easily install a command (even if you don't have homebrew) and it's way simpler to unit test.

Unicode Handling

Unicode character is not displayed correctly, and unicode filename cannot be recognized, either.

To reproduce:

git init .
mkdir test
touch test/test
touch test/简体中文
git add test
git config core.quotepath false

Case 1

Expected output of LANG=C git status | fpp:

On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   test/test
    new file:   test/简体中文

Actural output:

On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   test/test
    new file:   test/��~@��~S中�~V~G

The 2nd "new file" cannot be selected.

Case 2

Actural output of LANG=zh_CN.UTF-8 git status | fpp


�~H~]��~K�~O~P交

��~A�~O~P交�~Z~D�~O~X�~[���~Z
  ��~H使�~T� "git rm --cached <file>..." �~R��~G��~Z~B��~X�~L���~I

V��VG件: test/test
V��VG件: test/��~@��S中�V~G


Allow selection of items interactively with search keywords

The basic idea is great... But manually picking a bunch of items is ok, but you should also be able to interactively search for items to add to the selection list. Why? Because sometimes, you have alot of matching files, and manually picking them is tedious. Regex's are ok, but only basic regexs are what 99% of people understand. Think as simple as . or *.jpg, or *.js, and you've reached 90% of the understanding of the regex crowd.

For example, say I was in interactive mode, and had selected a few files by hitting f on each file.

I should also be able to enter "search mode" by typing / and then specifying a search query like the following:

test ez ab super$ ^black

which would match any file that has:

  • the words test, ez, ab in their filename
  • begins with the world black
  • ends with the word super
  • the results of this search would be shown in a filtered search result, and users could select matching items in this sub search by using the f shortcut.

If you did this.... this tool would be extra awesome!

False positive on `and/or`

As part of its output, git status prints this:

use "git add" and/or "git commit -a"

PathPicker picks up and/or as a path. I don't know if excluding and/or specifically is a good idea, but given the popularity of git, I think that use "git add" and/or "git commit -a" could be specifically excluded.

Fails when relative path is not prepended with "./"

Doesn't play well with ack (or any other tool with similar output) because ack does not prepend a "./" to the file list returned from . E.g.

ack -l 'foo'
junk/foo/bar.txt

ack -l 'foo' | fpp <------- Does not work needs ./junk/foo/bar.txt instead.

Arbitrary command mode doesn't have aliases or shell functions

When executing a command in arbitrary command mode, fpp is unaware of any aliases or shell functions I may have defined in my .zshrc (I'm using zsh but I've tested this in bash as well).

For example I have an alias gco="git checkout"and running gco in the arbitrary command mode gives:

.fbPager.sh: line 4: gco: command not found

choose.py Traceback when running fpp

Hi all,

I'm assuming this is either something I did or just an environment error but I'm not able to get the tool working on one of my notebooks. Here is what I'm seeing:

☁  jkup.github.io [master] ⚡ brew install fpp
==> Downloading https://homebrew.bintray.com/bottles/fpp-0.5.5.yosemite.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/fpp-0.5.5.yosemite.bottle.tar.gz
==> Pouring fpp-0.5.5.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/fpp/0.5.5: 11 files, 80K
☁  jkup.github.io [master] ⚡ fpp
Using old result...
Traceback (most recent call last):
  File "/usr/local/Cellar/fpp/0.5.5/libexec/src/choose.py", line 56, in <module>
    curses.wrapper(doProgram)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/local/Cellar/fpp/0.5.5/libexec/src/choose.py", line 27, in doProgram
    screen.control()
  File "/usr/local/Cellar/fpp/0.5.5/libexec/src/screenControl.py", line 275, in control
    self.printAll()
  File "/usr/local/Cellar/fpp/0.5.5/libexec/src/screenControl.py", line 493, in printAll
    self.printChrome()
  File "/usr/local/Cellar/fpp/0.5.5/libexec/src/screenControl.py", line 503, in printChrome
    self.helperChrome.output(self.mode)
  File "/usr/local/Cellar/fpp/0.5.5/libexec/src/screenControl.py", line 63, in output
    curses.curs_set(INVISIBLE_CURSOR)
_curses.error: curs_set() returned ERR

My current version of python is 2.7.9

☁  jkup.github.io [master] ⚡ python --version
Python 2.7.9

I tried it in both zsh and bash but getting the same errors. Not sure if there is any other helpful info I can include. Would love it if you all had any suggestions!

navigate by text line, not matched line

I'd like to be able to navigate up and down by line, and not automatically jump to the next line match. I'd imagine we could add a mode to flip the navigation keys into, or maybe alternately add new keys.

I'd prefer the former. I'd also like it to be a --command-line-switch so it can be passed in all the time.

I'll submit a PR for this sometime soon, as it would make path picker easier to use for me. Unless someone objects strongly, I'll implement a text-mode versus a match-mode, and have a key to flip between the two, and a command line option. And update the docs. and add it to the menu. Whew.

Allow use of shell aliases

I have a ton of git aliases and would like to use them with command mode. Otherwise the mode is practically worthless.

fbPager.sh: line 4: gco: command not found

Ctrl + C quits with exception

Traceback (most recent call last):
  File "/usr/local/Cellar/fpp/0.5.3/libexec/src/choose.py", line 58, in <module>
    curses.wrapper(doProgram)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/local/Cellar/fpp/0.5.3/libexec/src/choose.py", line 30, in doProgram
    screen.control()
  File "/usr/local/Cellar/fpp/0.5.3/libexec/src/screenControl.py", line 262, in control
    inKey = self.getKey()
  File "/usr/local/Cellar/fpp/0.5.3/libexec/src/screenControl.py", line 490, in getKey
    charCode = self.stdscr.getch()
KeyboardInterrupt

PathPicker could be pure Python (no bash script)

@zmwangx posted an example script of this:

https://gist.github.com/zmwangx/23806da530a39bb1c0cf

Rather than use bash to redirect stdin and connect to tty, we could do it all in pure python. Not sure what the big benefits would be here besides not having to mix languages and all of that (and easier option handling).

It was pure python we could distribute via pip which means easy installation for linux users, but then we would have duplication between homebrew and pip which is discouraged. should file to historical reasons though

fpp fails when called from a symlink in Linux

I'm creating an Arch package for PathPicker right now but I can't make a symlink to fpp work. This is the error I get:

/home/lsmag/my-symlink-fpp: line 18: cd: /home/lsmag//home/lsmag/PathPicker: No such file or directory
python2: can't open file '/src/processInput.py': [Errno 2] No such file or directory
python2: can't open file '/src/choose.py': [Errno 2] No such file or directory
:D

As you can see, the problem is /home/lsmag//home/lsmag/PathPicker = /home/lsmag/ + /home/lsmag/PathPicker, which is the predictable output of both dirname and readlink.

Using readlink -f, however, the command runs just fine. This is how it is on my machine now:

while [ -h "$WHEREAMI" ]; do
  WHEREAMI=$(readlink -f "$WHEREAMI")
done

I don't know if it still works on Macs, though.

line selection mode

Detecting paths is cool and everything, but I think it would be even more useful if there was a mode that treats every full input line as a "filename" (or other single parameter) and passes all selected lines to the output command, either one-by-one, or space-separated on the command line.

If this sounds useful to anyone else, I'll try to implement it and submit a pull request. It definitely seems to me like an entirely useful mode of operation.

By the way, thanks for fpp, it's a really awesome tool.

Linux packages

It would be good to have Linux packages available, at least .deb and .rpm versions. I don't know anyone that uses Linuxbrew, it doesn't seem ideal on Linux when better solutions exist.

The HHVM team distribute Linux packages, you could probably see how they do it.

Doesn't detect files without extensions

You can reproduce this issue by putting a Makefile or Dockerfile in a directory and ls | fpp. It will work with other files in the directory that have an extension.

BashRC

It'd be nice to load up your .bachrc and .bash_profile in command mode so you can use your aliases etc.

Doesn't handle paths with spaces in them

Both the highlighting and file-opening are tripped up by paths with spaces in them.

I tested with the output of OS X's mdfind -name foo (one path per line) piped into fpp.

How to make fpp only output the file list, so that you can plug in any file picker

Hi,

I already use https://github.com/junegunn/fzf as my general fuzzyfinder, and would really enjoy using the calculated filenames of fpp to feed into fzf. Is it possible to only output the list of files, instead of giving always a UI ?
It would also make more sense because a unix tool should try to do one thing well. I think with this in mind, it would even make sense to have two utilities that could together work as a path picker : the first one which does only the conversion from an output to a list of filenames, the second one which gives an UI to select one or more elements from a list.

Hope that you agree with that.

Allow specifying command as an argument to fpp

Would this be possible? Something like:

git status | fpp -c 'git add'

So that the default action is overridden and I can just hit 'enter' after selecting files to run git add on them.

Canceling (Control-c) a command produces noisy output

If I'm not mistaken, canceling CTRL+c should produce no output like most/all other commands.

Currently, this is what happens (on Ubuntu bash 4.2 at least, untested elsewhere) :

$ grep -ir 'foo' . | fpp
^CTraceback (most recent call last):
  File "/usr/local/PathPicker/src/processInput.py", line 144, in <module>
    doProgram()
  File "/usr/local/PathPicker/src/processInput.py", line 120, in doProgram
    lineObjs = getLineObjs()
  File "/usr/local/PathPicker/src/processInput.py", line 102, in getLineObjs
    inputLines = sys.stdin.readlines()
KeyboardInterrupt
Nothing to do!
:D

breaks when the file path contains duplicate dir names

git diff --stat
tweets/server/src/main/scala/com/twitter/tweets/Tweets.scala | 17 +++++++++++++---

git diff --stat | fpp
.../tweets/Tweets.scala | 17 ++++-

when you navigate to the item in fpp it attempts to open .../tweets/Tweets.scala which doesn't exist. The full path that's printed out when not using fpp is the correct path.

No available formula when installing via brew.

Gave following command a go from the project homepage, and saw the following:

~|⇒ brew install fpp
Error: No available formula for fpp
Searching formulae...
Searching taps...
~|⇒

Git installation troubles

I have a couple issues with the installation via git. I'm on OS X 10.10.3 with Python 2.7.6.

  1. The installation instructions create a cyclic symbolic link: ls -ltr | tail -n 1

lrwxr-xr-x (etc) fpp -> ./fpp

Adjusting the ln command to use the full path for the source fixes that.

  1. After the symbolic link is setup correctly I get the following error when running fpp --help:

/usr/local/bin/fpp: line 18: cd: /usr/local/bin//usr/local/PathPicker: No such file or directory
python: can't open file '/src/printHelp.py': [Errno 2] No such file or directory

I have placed PathPicker in /usr/local/PathPicker and linked the binary to /usr/local/bin/fpp.

Incorrect matching on files with multiple dots

If you have a file like "Company.Project.sln" or "archive.tar.gz", the highlighting and file name matching are incorrect. For example, fpp highlight and try to execute a command on "Project.sln" or "tar.gz".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.