about summary refs log tree commit diff stats
path: root/home-manager
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2023-05-28 22:10:24 +0200
committerSoispha <soispha@vhack.eu>2023-05-28 22:10:24 +0200
commite5af81a5f9d9d3a2af0d3e970815e3c73beb0840 (patch)
treea8acf6adde5c6f509bf523c28d4243869a3d1107 /home-manager
parentFix(bootstrap): Quote scripts (diff)
downloadnixos-config-e5af81a5f9d9d3a2af0d3e970815e3c73beb0840.tar.gz
nixos-config-e5af81a5f9d9d3a2af0d3e970815e3c73beb0840.zip
Fix(hm/conf/lf/cmds): Rework some of them
Diffstat (limited to '')
-rwxr-xr-xhome-manager/config/lf/commands/scripts/archive42
-rwxr-xr-xhome-manager/config/lf/commands/scripts/broot_jump4
-rwxr-xr-xhome-manager/config/lf/commands/scripts/chmod2
-rwxr-xr-xhome-manager/config/lf/commands/scripts/dl_file6
-rwxr-xr-xhome-manager/config/lf/commands/scripts/dragon6
-rwxr-xr-xhome-manager/config/lf/commands/scripts/dragon_individual6
-rwxr-xr-xhome-manager/config/lf/commands/scripts/dragon_stay6
-rwxr-xr-xhome-manager/config/lf/commands/scripts/fzf_jump4
-rwxr-xr-xhome-manager/config/lf/commands/scripts/mk_dir20
-rwxr-xr-xhome-manager/config/lf/commands/scripts/mk_file19
-rwxr-xr-xhome-manager/config/lf/commands/scripts/mk_ln4
-rwxr-xr-xhome-manager/config/lf/commands/scripts/mk_scr29
-rwxr-xr-xhome-manager/config/lf/commands/scripts/open2
-rwxr-xr-xhome-manager/config/lf/commands/scripts/set_wall_paper2
-rwxr-xr-xhome-manager/config/lf/commands/scripts/stripspace8
-rwxr-xr-xhome-manager/config/lf/commands/scripts/trash15
-rwxr-xr-xhome-manager/config/lf/commands/scripts/unarchive11
17 files changed, 132 insertions, 54 deletions
diff --git a/home-manager/config/lf/commands/scripts/archive b/home-manager/config/lf/commands/scripts/archive
index 617a4ace..3d267fa1 100755
--- a/home-manager/config/lf/commands/scripts/archive
+++ b/home-manager/config/lf/commands/scripts/archive
@@ -9,30 +9,46 @@ SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 # times.
 set -f
 
-archivers=$(tmp 'echo "gzip xz 7z zip"');
+archivers="$(tmp 'echo "gzip xz 7z zip"')";
 
-readp "File Name: " name;
+prompt "Archive name: "
+name=""
+while [ -z "$name" ] || [ -e "$name" ]
+do
+  read -r name
+  if [ -e "$name" ]; then
+    prompt "Archive already exists, overwrite [y|N]: "
+    read -r ans
 
-FX="$(awk -v Root="$(if [ "$(pwd)" = "/" ]; then pwd; else echo "$(pwd)/";fi)" '{
-for (i=1; i<=NF; i++) {
-    gsub(Root, "", $i);
-    print $i;
-}
-}' "$(tmp "echo \"$fx\" | tr '\n' ' '")")";
+    if [ "$ans" = "y" ]; then
+      break
+    else
+      prompt "Archive name: "
+    fi
+  fi
+done
 
-case $(awk '{for (i=1; i<=NF; i++) print $i}' $archivers | fzf) in
+root="$(if [ "$(pwd)" = "/" ]; then pwd; else echo "$(pwd)/";fi)";
+
+# fx contains all selected file name separated by a newline
+while read -r raw_file; do
+    file="$(echo "$raw_file" | sed "s|$root||")";
+    set -- "$@" "$file";
+done < "$(tmp "echo '$fx'")";
+
+case "$(awk '{for (i=1; i<=NF; i++) print $i}' "$archivers" | fzf)" in
     "gzip")
-        tar -czf "$name".tar.gz $FX
+        tar -czf "$name".tar.gz "$@"
         ;;
     "xz")
-        tar -cf "$name".tar $FX
+        tar -cf "$name".tar "$@"
         xz -z -9 -e -T0 "$name".tar
         ;;
     "7z")
-        7z a "$name".7z $FX
+        7z a "$name".7z "$@"
         ;;
     "zip")
-        zip --symlinks -r "$name".zip $FX
+        zip --symlinks -r "$name".zip "$@"
         ;;
 esac
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/broot_jump b/home-manager/config/lf/commands/scripts/broot_jump
index 6ff63ce9..ea8a8b8d 100755
--- a/home-manager/config/lf/commands/scripts/broot_jump
+++ b/home-manager/config/lf/commands/scripts/broot_jump
@@ -4,7 +4,7 @@
 SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
 tmp=$(mktmp)
-res="$(broot --outcmd $tmp && cat $tmp | sed 's/cd //')"
+res="$(broot --outcmd "$tmp" && sed 's/cd //' "$tmp")"
 
 if [ -f "$res" ]; then
     cmd="select"
@@ -12,5 +12,5 @@ elif [ -d "$res" ]; then
     cmd="cd"
 fi
 
-lf -remote "send $id $cmd \"$res\""
+lf -remote "send '$id' '$cmd' '$res'"
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/chmod b/home-manager/config/lf/commands/scripts/chmod
index bafb38c9..92f75e60 100755
--- a/home-manager/config/lf/commands/scripts/chmod
+++ b/home-manager/config/lf/commands/scripts/chmod
@@ -3,7 +3,7 @@
 # shellcheck source=/dev/null
 SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
-readp "Mode Bits: " bits
+readp "Mode bits: " bits
 
 while read -r file; do
     chmod "$bits" "$file"
diff --git a/home-manager/config/lf/commands/scripts/dl_file b/home-manager/config/lf/commands/scripts/dl_file
index 0988bca6..13d294a8 100755
--- a/home-manager/config/lf/commands/scripts/dl_file
+++ b/home-manager/config/lf/commands/scripts/dl_file
@@ -5,12 +5,12 @@ SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
 # Provides the ability to download a file by dropping it into a window
 
-url=$(dragon -t -x)
+url="$(dragon -t -x)"
 
 if [ -n "$url" ]; then
   prompt "File Name: "
   name=""
-  while [ -z $name ] || [ -e $name ]
+  while [ -z "$name" ] || [ -e "$name" ]
   do
     read -r name
     if [ -e "$name" ]; then
@@ -28,6 +28,6 @@ if [ -n "$url" ]; then
   # Download the file with curl
   [ -n "$name" ] && curl -o "$name" "$url" || die "curl failed"
 else
-  die "Url is null!"
+  die "URL is null!"
 fi
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/dragon b/home-manager/config/lf/commands/scripts/dragon
index a6fe0355..0978502b 100755
--- a/home-manager/config/lf/commands/scripts/dragon
+++ b/home-manager/config/lf/commands/scripts/dragon
@@ -3,5 +3,9 @@
 # shellcheck source=/dev/null
 SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
-dragon -a -x "$fx"
+while read -r file; do
+    set -- "$@" "$file"
+done < "$(tmp "echo '$fx'")"
+
+dragon -a -x "$@"
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/dragon_individual b/home-manager/config/lf/commands/scripts/dragon_individual
index 1cec01b2..f80bcd31 100755
--- a/home-manager/config/lf/commands/scripts/dragon_individual
+++ b/home-manager/config/lf/commands/scripts/dragon_individual
@@ -3,5 +3,9 @@
 # shellcheck source=/dev/null
 SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
-dragon "$fx"
+while read -r file; do
+    set -- "$@" "$file"
+done < "$(tmp "echo '$fx'")"
+
+dragon "$@"
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/dragon_stay b/home-manager/config/lf/commands/scripts/dragon_stay
index f0379680..05eb606c 100755
--- a/home-manager/config/lf/commands/scripts/dragon_stay
+++ b/home-manager/config/lf/commands/scripts/dragon_stay
@@ -3,5 +3,9 @@
 # shellcheck source=/dev/null
 SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
-dragon -a "$fx"
+while read -r file; do
+    set -- "$@" "$file";
+done < "$(tmp "echo '$fx'")"
+
+dragon -a "$@"
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/fzf_jump b/home-manager/config/lf/commands/scripts/fzf_jump
index 31fad6ef..ef4b510b 100755
--- a/home-manager/config/lf/commands/scripts/fzf_jump
+++ b/home-manager/config/lf/commands/scripts/fzf_jump
@@ -4,10 +4,12 @@
 SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
 res="$(fd . --maxdepth 3 | fzf --header='Jump to location')"
+
 if [ -f "$res" ]; then
     cmd="select"
 elif [ -d "$res" ]; then
     cmd="cd"
 fi
-lf -remote "send $id $cmd \"$res\""
+
+lf -remote "send '$id' '$cmd' '$res'"
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/mk_dir b/home-manager/config/lf/commands/scripts/mk_dir
index e24c9163..7793bad0 100755
--- a/home-manager/config/lf/commands/scripts/mk_dir
+++ b/home-manager/config/lf/commands/scripts/mk_dir
@@ -3,6 +3,22 @@
 # shellcheck source=/dev/null
 SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
-readp "Directory Name: " dir
-mkdir "$dir"
+prompt "Directory Name: "
+name=""
+while [ -z "$name" ] || [ -e "$name" ]
+do
+  read -r name
+  if [ -e "$name" ]; then
+    prompt "Directory already exists, overwrite [y|N]: "
+    read -r ans
+
+    if [ "$ans" = "y" ]; then
+      break
+    else
+      prompt "Directory Name: "
+    fi
+  fi
+done
+
+mkdir "$name"
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/mk_file b/home-manager/config/lf/commands/scripts/mk_file
index 5c98b400..11cac9b3 100755
--- a/home-manager/config/lf/commands/scripts/mk_file
+++ b/home-manager/config/lf/commands/scripts/mk_file
@@ -3,6 +3,23 @@
 # shellcheck source=/dev/null
 SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
-readp "File Name: " name
+prompt "File name: "
+name=""
+while [ -z "$name" ] || [ -e "$name" ]
+do
+  read -r name
+  if [ -e "$name" ]; then
+    prompt "File already exists, overwrite [y|N]: "
+    read -r ans
+
+    if [ "$ans" = "y" ]; then
+      break
+    else
+      prompt "File name: "
+    fi
+  fi
+done
+
+touch "$name"
 "$EDITOR" "$name"
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/mk_ln b/home-manager/config/lf/commands/scripts/mk_ln
index 7d626345..6563f29b 100755
--- a/home-manager/config/lf/commands/scripts/mk_ln
+++ b/home-manager/config/lf/commands/scripts/mk_ln
@@ -5,12 +5,12 @@ SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
 while IFS= read -r i;do
     set -- "$@" "$i"
-done < "$(tmp 'cat ~/.local/share/lf/files')"
+done < "$HOME"/.local/share/lf/files
 
 mode="$1"
 shift
 
-if [ "$#" -lt 1 ]; then
+if [ "$#" -eq 0 ]; then
     msg "no files to link"
     exit 0
 fi
diff --git a/home-manager/config/lf/commands/scripts/mk_scr b/home-manager/config/lf/commands/scripts/mk_scr
index 99f9f1d6..2f265aad 100755
--- a/home-manager/config/lf/commands/scripts/mk_scr
+++ b/home-manager/config/lf/commands/scripts/mk_scr
@@ -3,20 +3,29 @@
 # shellcheck source=/dev/null
 SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
-script=$(mktmp)
-cat "%SHELL_LIBRARY_TEMPLATE" > "$script"
 
-readp "Script Name: " script_name
-scr="$(pwd)"/"$script_name"
+prompt "Script name: "
+name=""
+while [ -z "$name" ] || [ -e "$name" ]
+do
+  read -r name
+  if [ -e "$name" ]; then
+    prompt "Script already exists, overwrite [y|N]: "
+    read -r ans
 
-while [ -e "$scr" ];do
-    readp "$script_name already exists, new name for script: " script_name
-    scr="$(pwd)"/"$script_name"
+    if [ "$ans" = "y" ]; then
+      break
+    else
+      prompt "Script Name: "
+    fi
+  fi
 done
 
-cat "$script" > "$scr"
-chmod +x "$scr"
+script="$(pwd)"/"$name"
+
+cat "%SHELL_LIBRARY_TEMPLATE" > "$script"
+chmod +x "$script"
+"$VISUAL" "$script"
 
 
-"$VISUAL" "$scr"
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/open b/home-manager/config/lf/commands/scripts/open
index a0257844..60382594 100755
--- a/home-manager/config/lf/commands/scripts/open
+++ b/home-manager/config/lf/commands/scripts/open
@@ -4,7 +4,7 @@
 SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
 case $(file --mime-type "$f" -bL) in
-    text/*|application/json) "$EDITOR" "$f";;
+    text/*|application/json|application/vnd.hp-HPGL) "$EDITOR" "$f";;
     image/*) "$IVIEWER" "$f";;
     *) xdg-open "$f";;
 esac
diff --git a/home-manager/config/lf/commands/scripts/set_wall_paper b/home-manager/config/lf/commands/scripts/set_wall_paper
index d4b38365..f7ecdf7a 100755
--- a/home-manager/config/lf/commands/scripts/set_wall_paper
+++ b/home-manager/config/lf/commands/scripts/set_wall_paper
@@ -5,6 +5,6 @@ SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
 die "No yet implemented" # TODO do what the 'die' says
 #sed -i "s,export AWMWALLPAPER='.*',export AWMWALLPAPER='${f}'," ${ZDOTDIR}/.zshenv
-#swaybg -i "$f" &
+#nohub swaybg -i "$f"
 #feh --bg-max --no-fehbg "$f"
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/stripspace b/home-manager/config/lf/commands/scripts/stripspace
index 59971a0b..2f047795 100755
--- a/home-manager/config/lf/commands/scripts/stripspace
+++ b/home-manager/config/lf/commands/scripts/stripspace
@@ -4,10 +4,10 @@
 SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 
 files=$(mktmp);
-echo "$fx" > $files;
+echo "$fx" > "$files";
 
 awk_source=$(mktmp);
-cat << OFT > $awk_source
+cat << OFT > "$awk_source"
 BEGIN {FS=" "}
 {for (i=1; i != NF + 1; i++)
     if (i == NF) {
@@ -21,11 +21,11 @@ OFT
 
 while read -r file; do
     dirty_name=$(mktmp)
-    basename "$file" > $dirty_name;
+    basename "$file" > "$dirty_name";
     clean_name=$(awk -f "$awk_source" "$dirty_name");
 
     [ -e "$clean_name" ] && die "file \"$clean_name\" already exists!";
-    mv "$(cat $dirty_name)" "$clean_name" || die "Move failed";
+    mv "$(cat "$dirty_name")" "$clean_name" || die "Move failed";
     lf -remote 'send reload'
 done < "$files";
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/trash b/home-manager/config/lf/commands/scripts/trash
index e3a5810b..c666b5eb 100755
--- a/home-manager/config/lf/commands/scripts/trash
+++ b/home-manager/config/lf/commands/scripts/trash
@@ -6,16 +6,21 @@ SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 trash_output=$(mktmp);
 expected_error_output=$(mktmp);
 
-# try trashy first
-nix run nixpkgs#trashy -- put "$fx" 2> $trash_output;
+while read -r file; do
+    set -- "$@" "$file"
+done < "$(tmp "echo '$fx'")"
 
-cat << EOF > $expected_error_output;
+# TODO why are we using trashy at all, when trash-cli can do everything?
+# try trashy first, trough nix because both trashy and trash-cli provide a trash command, which conflicts
+nix run nixpkgs#trashy -- put "$@" 2> "$trash_output";
+
+cat << EOF > "$expected_error_output";
 error: Error during a \`trash\` operation: Unknown { description: "Path: '\"/.Trash-1000\"'. Message: Permission denied (os error 13)" }
 EOF
 
-if [ "$(cat $expected_error_output)" = "$(cat $trash_output)" ];then
+if [ "$(cat "$expected_error_output")" = "$(cat "$trash_output")" ];then
     warning "Deleting with trash-cli to the /.Trash folder";
     # this file could not be trashed because it is on the tempfs volume, trash-cli can do this this
-    printf "%s" "$fx" | tr '\n' ' ' | xargs trash-put;
+    trash-put "$@";
 fi
 # vim: ft=sh
diff --git a/home-manager/config/lf/commands/scripts/unarchive b/home-manager/config/lf/commands/scripts/unarchive
index b0e3ab10..228cdf99 100755
--- a/home-manager/config/lf/commands/scripts/unarchive
+++ b/home-manager/config/lf/commands/scripts/unarchive
@@ -6,16 +6,17 @@ SHELL_LIBRARY_VERSION="1.1.3" . %SHELL_LIBRARY_PATH
 # extract the current file with the right command
 # (xkcd link: https://xkcd.com/1168/)
 set -f
+# TODO add support for multiple files at once
 case "$f" in
-    *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
-    *.tar.gz|*.tgz) tar xzvf $f;;
-    *.tar.xz|*.txz) tar xJvf $f;;
-    *.zip) unzip $f;;
+    *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf "$f";;
+    *.tar.gz|*.tgz) tar xzvf "$f";;
+    *.tar.xz|*.txz) tar xJvf "$f";;
+    *.zip) unzip "$f";;
     *.rar)
         die "rar is a unfree format!"
         #unrar x $f
         ;;
-    *.7z) 7z x $f;;
+    *.7z) 7z x "$f";;
     *) die "Unsupported format" ;;
 esac
 # vim: ft=sh