You are not logged in.

#1 2010-02-08 21:15:56

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Prompt Command File Manager: tiny bash FM

Last year pyfmii, now this. What's with these crazy file managers.

http://paste.pocoo.org/show/175499/

wget http://paste.pocoo.org/raw/175499/ -O ~/bin/pcfm; chmod +x ~/bin/pcfm
PROMPT_COMMAND=pcfm

By avoiding ncurses the program only takes up a few lines and doesn't clear the screen (and speed is still OK). It can paste right into the bash prompt using xdotool and xsel for a very transparent approach to the "subshell" in some file managers (like mc).

Features include bookmarks (you can actually call the program as a general selector for a list (try pcfm ls /)), sessions to keep track of last selected/marked files in a dir, searching in the list, some navigation things like trying to find the closest match when the previously selected item was deleted and auto-selecting the parent directory on `cd ..`, and a launcher for filenames.

It can generate the file list with any command you want, but will need a few functions to get the filename, and tell whether it's a directory and such. I have added a few of these "profiles".

The bad thing is that it needs xdotool and xsel, which I mentioned in this thread. xdotool can give bugs (I ran into shift lock a lot, which can be avoided by using an emulated click instead of Shift+Insert), will be a bit slow, and when you use it to paste, the mouse needs to be on the window. I actually wrote a function that moves the mouse on the window! So that is quite bad.

On the other hand, if a string only has ascii ([[:print:]] in C locale), it can be typed by `xdotool type --window xxx ...`, and xsel and pasting won't be needed. This speeds things up and makes it a little more stable (mouse doesn't have to be on the window, etc).

Anyway, if you use screen and like this file manager, be sure to try the different approach in the linked thread.

Screenshot:
Screenshot? Try your ls alias. On a related note, make sure you have a good LS_COLORS variable.

Offline

#2 2010-02-09 23:21:11

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

I did the screen version
http://paste.pocoo.org/show/175947/
wget http://paste.pocoo.org/raw/175947/  -O ~/bin/pcfm; chmod +x ~/bin/pcfm
PROMPT_COMMAND=pcfm

So far it works quite well, except the .. entry is too short sometimes (because it's generated with a separate ls -d .. command). I made some small improvements, but just for more efficient code, and fixing odd bugs. I got some of the function key scancodes for xterm/screen wrong, I haven't seen vte and such, but I think it's similar (should be easy to spot/fix)

I do have a more dmenu idea in mind, I started thinking about this a few weeks ago (that lead to this file manager) but couldn't figure out how to handle some things, but now that I have come this far I want to give it another shot. E.g. something like
ls -l | list-selector --preselect 4.0K\ directory1 --premark 4.0K\ directory2 --quit 'f1,f2,f3,f4,f5,f6,f7,f8,enter,a-z' | (output: "key" \n (selected) 4.0K directory1 \n (marked) 4.0K directory2 ) | session_management | sed '2,${s/fix filenames/}' | get the right command | screen paste/xsel/echo/set variables
(so it would do exactly the same)

Good idea? What sort of features would you want in that? Bash half screen control sequences or Python full screen curses?

Offline

#3 2010-02-10 17:15:34

Echtor2oo3
Member
From: Germany
Registered: 2009-05-12
Posts: 10
Website

Re: Prompt Command File Manager: tiny bash FM

Nice..
but take a look at bashc -> http://aur.archlinux.org/packages.php?ID=19368

bashc1.png

btw here is a fixed pastelink:
wget http://echtor.net/paste/442563.txt  -O ~/bin/pcfm; chmod +x ~/bin/pcfm
(http://echtor.net/paste.php)

Last edited by Echtor2oo3 (2012-05-02 15:07:46)

Offline

#4 2010-02-12 10:25:48

aeosynth
Member
From: California
Registered: 2010-02-06
Posts: 114
Website

Re: Prompt Command File Manager: tiny bash FM

This is pretty cool. A couple things I'd like to see:
bind left-arrow to 'up'
bind right-arrow to 'open'
vi bindings
--help

and a bug report:
this gives errors when .pcfm_session doesn't exist, instead of just creating it and shutting up.

Offline

#5 2010-02-12 11:28:58

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

@Echtor2oo3:
Yeah bashc does get that right, I don't remember exactly though, I tried this out last year, I'll give it another whirl for ideas.

@aeosynth:
Thanks, I cut out a bit too much in the screen approach too.

I am now working on splitting it up in several applications like I said above. I think it will do a lot better for adding features and bugfixing.
The display is almost done, try it out, tell me if you want some more vim keys, I thought ":" would be like F2 where you can perform a command on the selection for instance. And some new features like "-c" that removes from the screen what it printed (should look good when you use it as a FM)
wget http://echtor2oo3.de/paste/9461251.txt -O ~/bin/pcfm; chmod +x ~/bin/pcfm

Offline

#6 2010-02-12 12:01:15

SoothingHorror
Member
From: United States
Registered: 2010-02-04
Posts: 5

Re: Prompt Command File Manager: tiny bash FM

Is there a way to see what this looks like? I won't have access to a Linux/BSD system until sometime this weekend.

Offline

#7 2010-02-12 13:45:34

Echtor2oo3
Member
From: Germany
Registered: 2009-05-12
Posts: 10
Website

Re: Prompt Command File Manager: tiny bash FM

SoothingHorror wrote:

Is there a way to see what this looks like? I won't have access to a Linux/BSD system until sometime this weekend.

Here:

thumb_pcfm.png

Last edited by Echtor2oo3 (2012-05-02 15:08:22)

Offline

#8 2010-02-12 13:54:00

aeosynth
Member
From: California
Registered: 2010-02-06
Posts: 114
Website

Re: Prompt Command File Manager: tiny bash FM

http://vifm.sourceforge.net/docs.html has useful bindings. The ones I would most want are g / G for move to top / bottom, and h / l for back / forward (not up / down).

Offline

#9 2010-02-12 18:00:27

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

Uh oh, while minimizing/splitting/dmenu'ing I am really stuck with the session management. It needs to read the input stream to know which items are selected/marked, but then, how do you pass this data to the display app? changing the stream is bad, using a temp file is pretty bad too. So that is off the table for now. I will add the latest features / bugfixes to a unified xsel / screen program.

Offline

#10 2010-02-12 21:49:27

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

wget http://echtor2oo3.de/paste/9578489.txt -O ~/bin/pcfm; chmod +x ~/bin/pcfm

Now it will do either -xsel (default) or -screen. The differentiation by LC_ALL=C /^[[:print:]]*$/ and a byte count under 240 seems to work great for determining whether to use the paste buffer or type/stuff directly.

When using -vim, any non-vim-bound key (so everything except q:, hjkl, HML, $0gG) will do nothing instead of either causing find-as-you-type or starting the bash prompt. I'm not sure if that's good though. You can get the shell then with q or :.

I kept the usage of `command | pcfm` instead of `pcfm command`

Offline

#11 2010-02-12 22:17:57

SoothingHorror
Member
From: United States
Registered: 2010-02-04
Posts: 5

Re: Prompt Command File Manager: tiny bash FM

Echtor2oo3 wrote:
SoothingHorror wrote:

Is there a way to see what this looks like? I won't have access to a Linux/BSD system until sometime this weekend.

Here:

http://echtor2oo3.de/thumb/thumb_pcfm.png

Thank you! wink

Offline

#12 2010-02-13 00:04:34

aeosynth
Member
From: California
Registered: 2010-02-06
Posts: 114
Website

Re: Prompt Command File Manager: tiny bash FM

[bug] I get errors when I use wget:

$ pcfm
bash: /home/james/bin/pcfm: /bin/bash^M: bad interpreter: No such file or directory

If I open the link in Firefox, then copy and paste it into a file, it works fine. Running a diff (but not vimdiff) shows that the wget version adds ^M to every line.

Is there any way to stay in pcfm until I exit, besides using PROMPT_COMMAND? If I use PROMPT_COMMAND, then I can navigate directories just fine, but when I'm done and want to start working, I keep getting prompted. If I don't use PROMPT_COMMAND, then I have to keep typing pcfm all the time.

[bug] In find-as-you-type mode (pcfm -f), filtering d does nothing.

[request] toggle hidden files with ^H.

Offline

#13 2010-02-13 00:51:18

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

You're right about dos-mode text-files, does wget do that or can Echtor fix it?

F10 will auto-run `unset PROMPT_COMMAND`, maybe that is what you want? You could set that to do on other keys like ESC & vim-mode q (maybe that should be the default).

Filtering will do so on the entire entry, so d will match all directories (in the "iso" profile) For example try uncommenting TYPE=minimal.

Hiding hidden files falls under what ls command you use. I will add a profile that does not show hidden files, and then add a binding for switching profiles (like bookmarks but then a profile list) and a key per profile (and ^H for iso/iso-no-hidden). The profile setting will then be stored per directory, so you can have only $HOME hide hidden files, and any directory without a profile will use the default (defined by TYPE= in the script)

Offline

#14 2010-02-13 04:16:59

aeosynth
Member
From: California
Registered: 2010-02-06
Posts: 114
Website

Re: Prompt Command File Manager: tiny bash FM

Why don't you just host this on github, instead of random pastebins? (no offense to Echtor)

Procyon wrote:

F10 will auto-run `unset PROMPT_COMMAND`, maybe that is what you want?

Yeah, that's exactly what I wanted. IMO pcfm should automatically set the prompt command to itself - it's meant for interactive use, right? I've got pcfmv aliased to 'PROMPT_COMMAND="pcfm -v"', and I made q unset the prompt; it's a lot nicer this way.

Procyon wrote:

Filtering will do so on the entire entry, so d will match all directories (in the "iso" profile)

Oh, I thought find-as-you-type searched filenames, but instead it filters filetypes?

A .pcfmrc would be nice, so we can easily change our profile options without having to dig through the program logic.

Last edited by aeosynth (2010-02-13 04:21:00)

Offline

#15 2010-02-13 12:34:50

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

EDIT: wget 'http://echtor2oo3.de/paste/9769876.txt' -O - | tr -d '\r' > ~/bin/pcfm; chmod +x ~/bin/pcfm
(before edit version: 'http://echtor2oo3.de/paste/7936610.txt', it didn't restore selected files if you didn't have a dir-specific profile)

github and an rc file is a bit too much for a tiny program. In a case like this, an rc file is good if you have frequent updates, but unless someone has more good feature requests, there won't be anything to update. (new profiles, keybindings, file associations, it's all up to the user)

I made the start of the file look more organized so it's easier to change. Note that F9 takes you immediately to edit the script.

find-as-you-type searches the entire line: directory entries start with d.

alias is a good idea (up to the user), auto-setting the prompt requires sending a command, so that's too tricky.

I added a command line switch -t, to set the default profile.

The profile keys are now:
^H: toggle iso / iso-no-hidden
(commented) ^H: iso-no-hidden
^S: time sorted (based on iso)
^E: extension sort (based on iso)
^T: traditional (full ls -l)
^I: iso (-g -G and long-iso time) (^I is also TAB)
^N: minimal (size, filename, ID character)
^U: custom (e.g. `find -maxdepth 1`, it brings up a prompt), since directory status can't be checked (actually you can, with `file`, I will look into it later), you have to type F2 and cd
^P: show the profile list and choose one (like bookmarks)

Last edited by Procyon (2010-02-13 13:28:46)

Offline

#16 2010-02-13 22:27:45

aeosynth
Member
From: California
Registered: 2010-02-06
Posts: 114
Website

Re: Prompt Command File Manager: tiny bash FM

[--vim/-v]: enable vim keys (hjkl,gG,$0,LKH,:q)

You should escape $0 so it doesn't expand into the scripts location.

Hardcoding hidden / no-hidden profiles seems hackish, could you instead make each profile's ls command check for a 'showhidden' variable?

The runner function looks weird as well - why not just honor the mimetypes in /usr/share/applications/mimeinfo.cache ? I would make just one exception for text files, where I would honor the EDITOR variable.

I'm complaining so much because I think this is almost exactly what I need smile.

Offline

#17 2010-02-14 00:13:10

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

The problem with a show_hidden variable is that it would need to be written to the session file along with the profile.

A very neat improvement would be to abandon profiles in favor of one single (per-directory) variable that contains a list of switches to pass to ls.

On the other hand that would introduce a lot of keybindings and/or a huge configuration screen, while a few profiles is all you need.

For mimetypes there is Xyne's mimeo, I added commented code for it in the very first version, it doesn't work correctly though:
#elif [ $1 = -enter ]; then mimeo -c "$fn" 2>/dev/null || echo ignore | cut -d' ' -f1 #your own mime handler?

mimeo writes everything to stdout so it needs some extra code. I'll write it tomorrow and in the mean time please check out this application and mimeman to see if that does what you want.

Offline

#18 2010-02-14 22:12:02

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

wget 'http://echtor2oo3.de/paste/7567553.txt' -O - | tr -d '\r' > ~/bin/pcfm; chmod +x ~/bin/pcfm

No more profiles!

^P will let you choose ls switches. There are some separate options that are either on/off and some groups like -l / -g / -n where only one will be on (it fixes it itself). I think this is how it is supposed to go, but I'm not an expert on ls. I saw some things like -c that rely on -t or -l, so I just grouped it with -t.
Although most switches having long and short, I just went for 1 set that is incompatible with the other. E.g. in the long-listing group of -l/-g/-n/-o, I went for --numeric-uid-gid instead of -n, so if you put -n in the defaults and then try to add -l, -n won't be removed.

The ls_change function from ^P also takes ls's arguments.
So ^H can do `ls_change --almost-all`, which will toggle dot-files.

The default for the current directory can be restored in ^P, and the script can be changed to update the default with the currently used. (so it will write to itself)

-m to get applications from mimeo (on enter)

Offline

#19 2010-02-15 00:19:02

aeosynth
Member
From: California
Registered: 2010-02-06
Posts: 114
Website

Re: Prompt Command File Manager: tiny bash FM

It doesn't work for me anymore - I'm using PROMPT_COMMAND, pressing enter brings me to the shell prompt, pressing enter again brings me back to the pcfm prompt, q and F10 don't unset the prompt.

[request]
alt+home to cd back to home, with a vim binding of 0 or ^.

Offline

#20 2010-02-15 09:02:36

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

Try to rename your pcfm.session, if it works without, see if there is an error in it.
Are you using --mimeo? What happens if you do run `mimeo -c file; echo $?` on the file?
If it still doesn't make sense run `bash -x pcfm`

For Alt+home, they key reader needs to convert further \x1b to ESC, it now outputs ESC\x1b[1~. It will output ESCESC[1~ in the next version.

For vim:
elif [ $vim = 1 ] && [ $key = 0 -o $key = ^ ]; then return="$CD ~"; noconfirm=1

(I'll add those to the next version and the alt+home binding)

BTW I could also add a something like this:
    else erase; echo "Unknown key: $key" >&2; echo -n "$key" | hexdump -C >&2; setup

Offline

#21 2010-02-15 20:59:11

aeosynth
Member
From: California
Registered: 2010-02-06
Posts: 114
Website

Re: Prompt Command File Manager: tiny bash FM

I removed my .pcfm_session, didn't help. I'm not using --mimeo, and I don't even have mimeo installed. Here's the output of `bash -x pcfm`; I try to enter my 'code' directory, and nothing happens.
http://omploader.org/vM2tkdA

To really capture the vim experience, you should probably beep on unknown keys wink.

If you want me to use this as a file manager, instead of just as a file browser, I need vim bindings for file management - dd to remove files, [cCsSaAiI] to rename files. And if you really want to be awesome, set the cursor position:
at the start of the new filename on [iI]
at the end of the new filename, but before the file extension, on a
at the end of the new filename on A.
For [cCsS], the new filename could be left blank.

Have you looked at vifm? You're basically competing against it in my mind.

Offline

#22 2010-02-15 21:52:25

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

Ah now I see why, the default input method isn't xsel like usual (I mess around with it a lot), so it's using the screen method while you aren't using GNU Screen. Change the comments for input=... or use pcfm -x.

I tried out vifm a few years ago, but I like to be able to start typing commands immediately like in mc.

Rename is one thing (F7 does this too) but putting the cursor in a certain spot isn't really possible with readline. I guess you could count the amount of bytes (actually, wc -m) while still in the script and send that amount of left arrow keys. (And hope it comes out well...)

[cCsS] would be like F6. And "A" is F7.

Interpreting dd is also a bit tricky. But I guess you could hard code a flag on the first d and unset it if the second key is not again d and if it is call the same code as F8.

Offline

#23 2010-02-15 22:30:48

aeosynth
Member
From: California
Registered: 2010-02-06
Posts: 114
Website

Re: Prompt Command File Manager: tiny bash FM

Setting input=xsel fixes this, thanks.

Offline

#24 2010-02-15 22:46:32

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

Uh oh, the script went beyond the maximum file size for Echtor's site.
wget http://paste.pocoo.org/raw/178512/ -O ~/bin/pcfm; chmod +x pcfm

I fixed a small Screen-stuff bug with \ or ' in the filename (I think this is because echo -e intercepted them but I just doubly escaped them for now), and I added an extra line if there is only 1 line because 1 line does not work with some escape sequences that treat an argument of 0 as 1. It shouldn't have any influence except being able to move to an empty space in an empty directory or when using a search that leaves only 1 item (if it leaves 0 items you get a prompt to do either cd . or cd ..).

I added the the keys you mentioned above,
"a" puts the cursor on the last dot, so if you start typing, you append to the filename but not the extension. Right or not?

Sending lots of left arrow keys at once seems to work fine.

And dd works but there is no indicator that d was pressed (pressing any non-d key will unflag it though like I said) I guess if there will be more like these double keys they should go in the prompt.

Offline

#25 2010-02-18 00:27:01

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Prompt Command File Manager: tiny bash FM

wget http://paste.pocoo.org/raw/179504/ -O ~/bin/pcfm; chmod +x ~/bin/pcfm

Lots of small additions: a scroll bar (it took a lot of fine-tuning), a line at the bottom with some information about the current mode and such, colors for the UI (it's just a cyan foreground), checking for screen's $STY or X's $DISPLAY and displaying a warning, toggling of vim mode (^V) and input mode (M-L), and some more vim chain binds like 5G (go to item 5), 5j (go down 5), 5 arrow key down, and 25%.

Offline

Board footer

Powered by FluxBB