aboutsummaryrefslogtreecommitdiff
path: root/vifm/scripts
diff options
context:
space:
mode:
authortrainytrain <trainytrain@rape.lol>2021-05-09 01:29:07 -0700
committertrainytrain <trainytrain@rape.lol>2021-05-09 01:29:07 -0700
commitc765e68f05bfe9f0d2e4990bdc8dfabf11cdbc87 (patch)
tree1dd446298beeb5d1a411d5516689dee8c2ee26ee /vifm/scripts
init
Diffstat (limited to 'vifm/scripts')
-rw-r--r--vifm/scripts/README6
-rwxr-xr-xvifm/scripts/vifmimg53
-rwxr-xr-xvifm/scripts/vifmrun15
3 files changed, 74 insertions, 0 deletions
diff --git a/vifm/scripts/README b/vifm/scripts/README
new file mode 100644
index 0000000..7694952
--- /dev/null
+++ b/vifm/scripts/README
@@ -0,0 +1,6 @@
+This directory is dedicated for user-supplied scripts/executables.
+vifm modifies its PATH environment variable to let user run those
+scripts without specifying full path. All subdirectories are added
+as well. File in a subdirectory overrules file with the same name
+in parent directories. Restart might be needed to recognize files
+in newly created or renamed subdirectories. \ No newline at end of file
diff --git a/vifm/scripts/vifmimg b/vifm/scripts/vifmimg
new file mode 100755
index 0000000..e5d8763
--- /dev/null
+++ b/vifm/scripts/vifmimg
@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+readonly ID_PREVIEW="preview"
+
+#AUTO_REMOVE="yes"
+# By enabling this option the script will remove the preview file after it is drawn
+# and by doing so the preview will always be up-to-date with the file.
+# This however, requires more CPU and therefore affects the overall performance.
+
+if [ -e "$FIFO_UEBERZUG" ]; then
+ if [[ "$1" == "draw" ]]; then
+ declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
+ [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
+ [path]="${PWD}/$6") \
+ > "$FIFO_UEBERZUG"
+
+ elif [[ "$1" == "videopreview" ]]; then
+ echo -e "Loading preview..\nFile: $6"
+ [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/"
+ [[ ! -f "/tmp${PWD}/$6.png" ]] && ffmpegthumbnailer -i "${PWD}/$6" -o "/tmp${PWD}/$6.png" -s 0 -q 10
+ declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
+ [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
+ [path]="/tmp${PWD}/$6.png") \
+ > "$FIFO_UEBERZUG"
+
+ elif [[ "$1" == "gifpreview" ]]; then
+ echo -e "Loading preview..\nFile: $6"
+ [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/" && convert -coalesce "${PWD}/$6" "/tmp${PWD}/$6/$6.png"
+ for frame in $(ls -1 /tmp${PWD}/$6/$6*.png | sort -V); do
+ declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
+ [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
+ [path]="$frame") \
+ > "$FIFO_UEBERZUG"
+ # Sleep between frames to make the animation smooth.
+ sleep .07
+ done
+
+ elif [[ "$1" == "pdfpreview" ]]; then
+ echo -e "Loading preview..\nFile: $6"
+ [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/"
+ [[ ! -f "/tmp${PWD}/$6.png" ]] && pdftoppm -png -singlefile "$6" "/tmp${PWD}/$6"
+ declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
+ [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
+ [path]="/tmp${PWD}/$6.png") \
+ > "$FIFO_UEBERZUG"
+
+ elif [[ "$1" == "clear" ]]; then
+ declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \
+ > "$FIFO_UEBERZUG"
+ [[ ! -z $AUTO_REMOVE ]] && [[ -f "/tmp${PWD}/$6.png" ]] && rm -f "/tmp${PWD}/$6.png"
+ [[ ! -z $AUTO_REMOVE ]] && [[ -d "/tmp${PWD}/$6/" ]] && rm -rf "/tmp${PWD}/$6/"
+
+ fi
+fi
diff --git a/vifm/scripts/vifmrun b/vifm/scripts/vifmrun
new file mode 100755
index 0000000..9eda32a
--- /dev/null
+++ b/vifm/scripts/vifmrun
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}"
+
+function cleanup {
+ rm "$FIFO_UEBERZUG" 2>/dev/null
+ pkill -P $$ 2>/dev/null
+}
+
+rm "$FIFO_UEBERZUG" 2>/dev/null
+mkfifo "$FIFO_UEBERZUG"
+trap cleanup EXIT
+tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser bash &
+
+vifm
+cleanup