diff options
author | Soispha <soispha@vhack.eu> | 2024-02-23 21:00:46 +0100 |
---|---|---|
committer | Soispha <soispha@vhack.eu> | 2024-02-23 21:18:34 +0100 |
commit | 2f1960bacc4b6956d0a4a2e80eb17014f1d6767d (patch) | |
tree | 8b7ae3da2dfec18f54bcf37cf0c8e3e909fe4cfe /hm/soispha/conf | |
parent | fix(hm/conf/lf/commands): Remove useless 'open_config' cmd (diff) | |
download | nixos-config-2f1960bacc4b6956d0a4a2e80eb17014f1d6767d.zip |
fix(hm/conf/lf/commands): Check for the file name with the extension added
Beforehand it resolved a name conflict based on the base name alone: ``` USER: script ALREADY_EXISTING_FILE: script ``` But the final script would then be named `script.sh`, thus, the check must include the `.sh`.
Diffstat (limited to 'hm/soispha/conf')
-rwxr-xr-x | hm/soispha/conf/lf/commands/scripts/archive.sh | 22 | ||||
-rwxr-xr-x | hm/soispha/conf/lf/commands/scripts/mk_scr_default.sh | 6 |
2 files changed, 22 insertions, 6 deletions
diff --git a/hm/soispha/conf/lf/commands/scripts/archive.sh b/hm/soispha/conf/lf/commands/scripts/archive.sh index 9ac07898..bee9c341 100755 --- a/hm/soispha/conf/lf/commands/scripts/archive.sh +++ b/hm/soispha/conf/lf/commands/scripts/archive.sh @@ -17,12 +17,28 @@ fx="$fx" fs="$fs" archivers="$(tmp echo gzip xz 7z zip)" +archiver="$(awk '{for (i=1; i<=NF; i++) print $i}' "$archivers" | fzf)" + +case "$archiver" in +"gzip") + ext=tar.gz + ;; +"xz") + ext=tar.xz + ;; +"7z") + ext=7z + ;; +"zip") + ext=zip + ;; +esac prompt "Archive name: " name="" -while [ -z "$name" ] || [ -e "$name" ]; do +while [ -z "$name" ] || [ -e "$name.$ext" ]; do read -r name - if [ -e "$name" ]; then + if [ -e "$name.$ext" ]; then prompt "Archive already exists, overwrite [y|N]: " read -r ans @@ -42,7 +58,7 @@ while read -r raw_file; do set -- "$@" "$file" done <"$(tmp echo "$fx")" -case "$(awk '{for (i=1; i<=NF; i++) print $i}' "$archivers" | fzf)" in +case "$archiver" in "gzip") tar -czf "$name".tar.gz "$@" ;; diff --git a/hm/soispha/conf/lf/commands/scripts/mk_scr_default.sh b/hm/soispha/conf/lf/commands/scripts/mk_scr_default.sh index 915725cc..7ca3759e 100755 --- a/hm/soispha/conf/lf/commands/scripts/mk_scr_default.sh +++ b/hm/soispha/conf/lf/commands/scripts/mk_scr_default.sh @@ -14,9 +14,9 @@ id="$id" prompt "Script name: " name="" -while [ -z "$name" ] || [ -e "$name" ]; do +while [ -z "$name" ] || [ -e "$name.sh" ]; do read -r name - if [ -e "$name" ]; then + if [ -e "$name.sh" ]; then prompt "Script already exists, overwrite [y|N]: " read -r ans @@ -30,7 +30,7 @@ done script="$(pwd)"/"$name" -cat "%SHELL_LIBRARY_TEMPLATE" >"$script" +cat "%SHELL_LIBRARY_TEMPLATE" >"$script.sh" chmod +x "$script" "$VISUAL" "$script" |