***
SFM - A DUAL PANE FILE MANAGER FOR FBPAD
$ source ~/koxtoolchain/refs/x-compile.sh kobo env bare
(Prepare build system as was done in Post #4 above.)
afify/sfm
https://github.com/afify/sfm
$ wget
https://github.com/afify/sfm/archive...gs/v0.4.tar.gz
$ mv v0.4.tar.gz sfm-v0.4.tar.gz
$ tar zxvf sfm-v0.4.tar.gz
$ cd sfm-0.4/
$ nano -l config.mk
Code:
...
14 CC = arm-kobo-linux-gnueabihf-gcc
...
$ make
$ file sfm
sfm: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.33, stripped
Copy the sfm binary to the /mnt/onboard/.adds/kordir/scripts/ folder on your Kobo.
# . /korenv.sh
# sfm
j/k to go down,up
h/l to traverse directories or open file
:q <RET> to quit viewing a file (vi is default viewer)
space to switch panes
b to open shell (CTRL-d to return to sfm)
. to toggle hidden files
CTRL-u to go up 3
CTRL-d to go down 3
q to quit sfm
***
We can customize the keydefs to make them more consistent with our other apps.
At the same time we can add fbpdf and elinks as default handlers:
* Update: added PageUp/PageDown key support, removed redundant ,/.
$ nano -l config.def.h
Code:
...
50 /* software */
51 static const char *mpv[] = { "mpv", "--fullscreen" };
52 static const char *elinks[] = { "elinks" };
53 static const char *fbpdf[] = { "fbpdf" };
...
58 /* extensions*/
59 static const char *images[] = { "bmp", "jpg", "jpeg", "png", "gif", "xpm" };
60 static const char *pdf[] = { "epub", "pdf" };
61 static const char *arts[] = { "xcf" };
62 static const char *html[] = { "htm", "html" };
...
69 static Rule rules[] = {
70 {videos, LEN(videos), mpv, LEN(mpv) },
71 {images, LEN(images), fbpdf, LEN(fbpdf) },
72 {pdf, LEN(pdf), fbpdf, LEN(fbpdf) },
73 {documents, LEN(documents), libreoffice, LEN(libreoffice) },
74 {arts, LEN(arts), gimp, LEN(gimp) },
75 {html, LEN(html), elinks, LEN(elinks) },
...
85 { {.ch = 'b'}, mv_ver, {.i = +8} },
86 { {.key = TB_KEY_PGUP}, mv_ver, {.i = +8} },
87 { {.key = TB_KEY_SPACE}, mv_ver, {.i = -8} },
88 { {.key = TB_KEY_PGDN}, mv_ver, {.i = -8} },
89 { {.ch = 'l'}, mvfwd, {.i = 0} },
90 { {.key = TB_KEY_ARROW_RIGHT}, mvfwd, {.i = 0} },
91 { {.key = TB_KEY_ENTER}, mvfwd, {.i = 0} },
92 { {.ch = 'h'}, mvbk, {.i = 0} },
93 { {.key = TB_KEY_ARROW_LEFT}, mvbk, {.i = 0} },
94 { {.key = TB_KEY_BACKSPACE}, mvbk, {.i = 0} },
95 { {.key = TB_KEY_BACKSPACE2}, mvbk, {.i = 0} },
...
110 { {.ch = 'B'}, opnsh, {0} },
111 { {.key = TB_KEY_TAB}, switch_pane, {0} },
112 { {.key = TB_KEY_CTRL_R}, refresh, {0} },
113 { {.ch = '\\'}, bkmrk, {.v = root} },
114 { {.ch = 'H'}, toggle_df, {0} },
...
$ rm config.h
$ make
Copy the new sfm binary to the /mnt/onboard/.adds/kordir/scripts/ folder on your Kobo.
# FBPDF_PERCENT=58 sfm
Our new keydefs are:
j/k to go down,up
(* DON'T PRESS ARROW_DOWN OR YOU WILL ENTER SHELL, CTRL-D TO EXIT)
(* DON'T PRESS ARROW_LEFT OR YOU WILL BE PROMPTED TO RENAME, RET TO KEEP NAME)
h/l to traverse directories or open file
BS/RET to traverse directories or open file
:q <RET> to quit viewing a file (vi is default viewer)
TAB to switch panes
B to open shell (CTRL-d to return to sfm)
H to toggle hidden files
b/PageUp to go up 8
space/PageDown to go down 8
q to quit sfm
Now, entering l/RET on a pdf/epub/image file now invokes fbpdf, while on an html file invokes elinks.
***
The vi editor is the default viewer, but we can override this with an environment variable SFM_VIEWER.
* Update: at the same time we can try to correct the errant left and down arrow behavior:
$ nano -l sfm.c
Code:
...
1861 editor[0] = getenv("SFM_VIEWER");
...
2000
2001 if (tb_select_input_mode(TB_INPUT_ALT) != TB_INPUT_ALT)
2002 if (tb_select_input_mode(TB_INPUT_ESC) != TB_INPUT_ESC)
2003 die("input error");
2004
...
$ make
# SFM_VIEWER=less sfm
Now, entering l/RET on a text file invokes the less pager instead of the vi editor, so you can use space/b for pagedown/pageup, and just q for quit.
We can create scripts to call sfm with the viewer we want:
* Update: Set TERM to linux instead of xterm to correct errant arrow key behavior. Unfortunately, same problem occurs if you press keys too quickly! But at least works if you go slow.
# vi /usr/bin/sfmless
Code:
export TERM=linux
SFM_VIEWER=less /mnt/onboard/.adds/kordir/scripts/sfm
# vi /usr/bin/sfmvi
Code:
export TERM=linux
SFM_VIEWER=vi /mnt/onboard/.adds/kordir/scripts/sfm
# vi /usr/bin/sfmnano
Code:
export TERM=linux
SFM_VIEWER=nano /mnt/onboard/.adds/kordir/scripts/sfm
# chmod 755 /usr/bin/sfmless
# chmod 755 /usr/bin/sfmvi
# chmod 755 /usr/bin/sfmnano
# sfmless
(can quit with q)
# sfmvi
(can quit with ESC then :q!)
# sfmnano
(haha, doesn't work unless you installed nano as in Post #3, and even then you would have to first run . /korenv.sh to set the PATH)
***
Our (revised) sfm keydefs:
obsoleted, see update 2
*** UPDATE ELINKS.CONF KEY BINDINGS ***
Update /mnt/onboard/.adds/kordir/.elinks/elinks.conf to harmonize elinks with new apps fbpdf and sfm:
REMOVE:
bind "main" "," = "history-move-back"
bind "main" "." = "history-move-forward"
bind "main" "#" = "toggle-numbered-links"
ADD:
bind "main" "H" = "history-manager"
bind "main" "h" = "history-move-back"
bind "main" "l" = "history-move-forward"
bind "main" "j" = "move-cursor-down"
bind "main" "k" = "move-cursor-up"
RESULT:
Use H instead of h for history
Use h/l instead of ,/. for move forward/back in history
Use j/k for for move cursor down/up
Use the default . to toggle displaying numbered links on page, so you can go directly to the link by entering the number.
***************************************
*** ALSO UPDATE /KORENV.SH ***
Update /korenv.sh to better work with new apps fbpdf and sfm:
REMOVE:
export TERM=xterm
ADD:
export TERM=linux
export FBPDF_PERCENT=58
***************************************
***
* UPDATE 2 - A KLUDGE/FIX FOR ERRANT DIRECTION KEYS:
A possible kludge/fix is to redefine key sequences to NOT be confused with the escape code sequences we are sending for the direction keys.
ANSI escape code sequences for direction keys:
<esc>[A - Up
<esc>[B - Down
<esc>[D - Left
<esc>[C - Right
Errant sfm direction key responses:
ARROW_DOWN - SHELL
ARROW_LEFT - RENAME
Our latest(after 1st update) sfm keydefs:
A undefined
B spawn a shell in the current directory
D duplicate file | directory recursively
C undefined
So we can try redefining these keys:
A up
B down
D left
C right
, duplicate file | directory recursively
S spawn a shell in the current directory
. toggle dotfiles
$ nano -l config.def.h
Code:
...
81 { {.ch = 'j'}, mv_ver, {.i = -1} },
82 { {.ch = 'B'}, mv_ver, {.i = -1} },
83 { {.key = TB_KEY_ARROW_DOWN}, mv_ver, {.i = -1} },
84 { {.ch = 'k'}, mv_ver, {.i = +1} },
85 { {.ch = 'A'}, mv_ver, {.i = +1} },
86 { {.key = TB_KEY_ARROW_UP}, mv_ver, {.i = +1} },
...
91 { {.ch = 'l'}, mvfwd, {.i = 0} },
92 { {.ch = 'C'}, mvfwd, {.i = 0} },
93 { {.key = TB_KEY_ARROW_RIGHT}, mvfwd, {.i = 0} },
94 { {.key = TB_KEY_ENTER}, mvfwd, {.i = 0} },
95 { {.ch = 'h'}, mvbk, {.i = 0} },
96 { {.ch = 'D'}, mvbk, {.i = 0} },
97 { {.key = TB_KEY_ARROW_LEFT}, mvbk, {.i = 0} },
98 { {.key = TB_KEY_BACKSPACE}, mvbk, {.i = 0} },
99 { {.key = TB_KEY_BACKSPACE2}, mvbk, {.i = 0} },
...
105 { {.ch = ','}, dupl, {0} },
...
114 { {.ch = 'S'}, opnsh, {0} },
...
118 { {.ch = '.'}, toggle_df, {0} },
...
$ rm config.h
$ make
Copy the new sfm binary to the /mnt/onboard/.adds/kordir/scripts/ folder on your Kobo.
# sfm
Direction keys now working, but colors in elinks a little off.
Change to export TERM=screen and all good.
So...
# vi /usr/bin/sfmless
Code:
export TERM=screen
SFM_VIEWER=less /mnt/onboard/.adds/kordir/scripts/sfm
# vi /usr/bin/sfmvi
Code:
export TERM=screen
SFM_VIEWER=vi /mnt/onboard/.adds/kordir/scripts/sfm
# vi /usr/bin/sfmnano
Code:
export TERM=screen
SFM_VIEWER=nano /mnt/onboard/.adds/kordir/scripts/sfm
# vi /korenv.sh
Code:
#!/bin/sh
export PATH=/mnt/onboard/.adds/kordir/scripts:/mnt/onboard/.adds/koreader/plugins/terminal.koplugin/:/mnt/onboard/.adds/koreader/scripts:$PATH
export LD_LIBRARY_PATH=/mnt/onboard/.adds/kordir/libs:/mnt/onboard/.adds/koreader/libs:$LD_LIBRARY_PATH
export TERM=screen
export FBPDF_PERCENT=58
export HOME=/mnt/onboard/.adds/kordir/
cd $HOME
alias ls='ls --color=never'
***
* UPDATE 3 - PUT HIGHLIGHTED FILE'S BASENAME ON STATUS BAR:
Helps identify currently selected file when running sfm in KOReader terminal.
$ nano -l sfm.c
Code:
...
284 static void
285 print_info(Pane *pane, char *dirsize)
286 {
287 char *sz, *ur, *gr, *dt, *prm, *nm;
288
289 dt = ecalloc(MAX_DTF, sizeof(char));
290 nm = basename(CURSOR(pane).name);
...
309 print_status(cstatus, "%02d/%02d %s %s:%s %s %s %s", pane->hdir,
310 pane->dirc, prm, ur, gr, dt, sz, nm);
...
$ make
Copy the new sfm binary to the /mnt/onboard/.adds/kordir/scripts/ folder on your Kobo.
Run sfm in KOReader terminal:
# . /korenv.sh
# sfm
***
Our (final?) sfm keydefs:
Normal Mode
q quit
h/left/BS back
j/down down
k/up up
l/right/RET open dir | file
g top
G bottom
b/PgUp scroll up
SPACE/PgDn scroll down
n create new file if not exists
N create new directory if not exists
d delete file | directory recursively
, duplicate file | directory recursively
y yank
p paste
P move
S spawn a shell in the current directory
c start change
cw rename
co change owner and group (chown)
cm change mode (chmod)
cf change flags (chflags | chattr)
cc exit change
cq exit change
. toggle dotfiles
v start visual mode
/ start filter
ENTER find filter
ESC exit filter
TAB switch pane
ctrl+r refresh panes
Visual Mode
j select down
k select up
d delete selection
v exit visual mode
q exit visual mode
ESC exit visual mode | change
***
* Edit : actually just leave default input mode - comment out the crap I put there (it interfered with ESC key use.)
$ nano -l sfm.c
Code:
...
2000 /*
2001 if (tb_select_input_mode(TB_INPUT_ALT) != TB_INPUT_ALT)
2002 if (tb_select_input_mode(TB_INPUT_ESC) != TB_INPUT_ESC)
2003 die("input error");
2004 */
...
* Edit : add a couple more bindings to elinks.conf to not interfere with screen utility.
Code:
...
bind "main" "Ctrl-a" = "none"
bind "main" "Ctrl-A" = "none"
set document.colors.use_document_colors = 0
...