Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
edi9999 opened this issue May 9, 2015 · 5 comments

Comments

@edi9999
Copy link

edi9999 commented May 9, 2015

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.

@pcottle
Copy link
Contributor

pcottle commented May 11, 2015

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.

Yeah, this has come up a bunch internally and externally. I'm a huge fan of the unix philosophy but I actually think a lot of the value of PathPicker is added by being a "one-stop shop" for everything you need to do with paths. Had we gone more unixy we would either have just:

  1. built the parsing of files and outputted those, or
  2. built the UI selector and worked with any kind of input

But neither of these would have been that great. With 1) developers would still have to do awkward xargs things (or put the command in a subshell like $(ls -l | fpp) which I find annoying). With 2) the input would require a lot of prep with regexes and sed to get into an acceptable format for selection (think of all the work git diff or git diff --stat requires)

so we had to go into brave new territory and do a very non-unixy thing here, but I think it ended up really striking a perfect spot between utility and simplicity.

@pcottle
Copy link
Contributor

pcottle commented May 11, 2015

Anyways, I think it'd be quite easy to fork this project and refactor it to just output the list of files (basically remove the $PYTHONCMD "$BASEDIR/src/choose.py" < /dev/tty line and simply print the list out from python), but I don't think this is something we can support easily since. Let me know if you need pointers on the fork though! Who knows, maybe the fork would become more popular one day :P

@pcottle pcottle closed this as completed May 11, 2015
@edi9999
Copy link
Author

edi9999 commented May 11, 2015

Hi, If I do the following:

function doProgram {
  # process input from pipe and store as pickled file
  $PYTHONCMD "$BASEDIR/src/processInput.py"
  # now close stdin and choose input...
  exec 0<&-
  # $PYTHONCMD "$BASEDIR/src/choose.py" < /dev/tty
  # execute the output bash script
  # sh ~/.fpp/.fpp.sh < /dev/tty
  cat ~/.fpp/.pickle
}

I don't get the list of filenames as a result. Where can I get the list of the possible files ?

Here is what I get with ls | /.fpp

(dp0
I0
ccopy_reg
_reconstructor
p1
(cformat
SimpleLine
p2
c__builtin__
object
p3
Ntp4
Rp5
(dp6
S'index'
p7
I0
sS'line'
p8
S'assets\n'
p9
sbsI1
g1
(cformat
LineMatch
p10
g3
Ntp11
Rp12
(dp13
g7
I1
sS'end'
p14
I15
sS'hovered'
p15
I00
sS'selected'
p16
I00
sS'start'
p17
I0
sS'num'
p18
I0
sS'file'
p19
S'./CONTRIBUTING.md'
p20
sS'originalFile'
p21
S'CONTRIBUTING.md'
p22
sS'group'
p23
S'CONTRIBUTING.md'
p24
sg8
S'CONTRIBUTING.md\n'
p25
sbsI2
g1
(g2
g3
Ntp26
Rp27
(dp28
g7
I2
sg8
S'fpp\n'
p29
sbsI3
g1
(g10
g3
Ntp30
Rp31
(dp32
g7
I3
sg14
I6
sg15
I00
sg16
I00
sg17
I0
sg18
I0
sg19
S'./fpp.rb'
p33
sg21
S'fpp.rb'
p34
sg23
S'fpp.rb'
p35
sg8
S'fpp.rb\n'
p36
sbsI4
g1
(g10
g3
Ntp37
Rp38
(dp39
g7
I4
sg14
I10
sg15
I00
sg16
I00
sg17
I0
sg18
I0
sg19
S'./index.html'
p40
sg21
S'index.html'
p41
sg23
S'index.html'
p42
sg8
S'index.html\n'
p43
sbsI5
g1
(g2
g3
Ntp44
Rp45
(dp46
g7
I5
sg8
S'LICENSE\n'
p47
sbsI6
g1
(g2
g3
Ntp48
Rp49
(dp50
g7
I6
sg8
S'PATENTS\n'
p51
sbsI7
g1
(g10
g3
Ntp52
Rp53
(dp54
g7
I7
sg14
I9
sg15
I00
sg16
I00
sg17
I0
sg18
I0
sg19
S'./README.md'
p55
sg21
S'README.md'
p56
sg23
S'README.md'
p57
sg8
S'README.md\n'
p58
sbsI8
g1
(g2
g3
Ntp59
Rp60
(dp61
g7
I8
sg8
S'scripts\n'
p62
sbsI9
g1
(g2
g3
Ntp63
Rp64
(dp65
g7
I9
sg8
S'src\n'
p66
sbs.% 

@edi9999
Copy link
Author

edi9999 commented May 11, 2015

Found how to make it work now, I will be releasing a fork

@pcottle
Copy link
Contributor

pcottle commented May 11, 2015

Yeah the issue with cat ~/.fpp/.pickle is that those are pickled bytes from python, not plaintext. Sounds like you figured it out but heres a simple way to print out all the files from the pickled state:

[pcottle:~/Dropbox (Facebook)/wip/PathPicker/src:master]$ python
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import format
>>> import pickle
>>> fileHandle = open('/Users/pcottle/.fpp/.pickle', 'rb')
>>> lineObjs = pickle.load(fileHandle)
>>> matches = [lineObj for i, lineObj in lineObjs.items() if not lineObj.isSimple()]
>>> for match in matches:
...   print match.getFile()
... 
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/assets/favicon.ico
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/assets/fpp-favicon.ico
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/assets/heading@2x.png
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/assets/launch_page.css
./index.html
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/scripts/buildAndTest.sh
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/scripts/makeDist.sh
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/src/colorPrinter.py
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/src/format.py
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/src/formattedText.py
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/src/processInput.py
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/src/screenControl.py
/Users/pcottle/Dropbox (Facebook)/wip/PathPicker/src/test.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants