forked from dylanaraps/shfm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
shfm-sxiv.diff
55 lines (51 loc) · 1.75 KB
/
shfm-sxiv.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
diff --git a/shfm b/shfm
index 0b227fc..5281926 100755
--- a/shfm
+++ b/shfm
@@ -110,6 +110,23 @@ cmd_run() {
hist=2
}
+cmd_select() {
+ # cmd_select reads sxiv's output to add the corresponding files to selected.
+ # cmd_select will break on files with tabs or newlines in their names.
+ # it can handle file names with spaces unless there're two or more in a row.
+ # cmd_select won't crash shfm when such filenames are read in, it just fails to mark files.
+ term_reset
+ printf %s "$@"
+ b=
+ for a in $("$@"); do
+ a="${a#./}"
+ [ -n "$b" ] && b="$b $a" || b="$a"
+ add_selected "$b" && unset b || b="$a"
+ done || :
+ term_setup
+ hist=2
+}
+
file_escape() {
tmp=$1 safe=
@@ -696,7 +713,8 @@ main() {
' r - bulk rename' \
' a - select all' \
' A - invert selection' \
- ' n - create new file or directory'
+ ' n - create new file or directory' \
+ ' s - select images with sxiv'
ltype=keybinds
;;
@@ -1117,6 +1135,16 @@ main() {
fi
;;
+ s?)
+ # open all images in current directory in sxiv
+ # images marked by sxiv will be read in through cmd_select and
+ # added to selected.
+ # there's currently no way to tell sxiv which files shfm has
+ # already marked so that sxiv can unmark them.
+ cmd_select 'sxiv' '-boqt' .
+ redraw "$@"
+ ;;
+
# handle keys which emit escape sequences
"$esc_c"*) state=1 ;;
'[1') state=2 ;;