aboutsummaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
Diffstat (limited to 'functions')
-rw-r--r--functions/7za.fish2
-rw-r--r--functions/alert.fish34
-rw-r--r--functions/check_install.fish27
-rw-r--r--functions/lscmd.fish2
-rw-r--r--functions/rchmod.fish5
-rw-r--r--functions/renlow.fish5
-rw-r--r--functions/rlsxattr.fish14
-rw-r--r--functions/rsdos.fish11
-rw-r--r--functions/rsmac.fish7
-rw-r--r--functions/rsxattr.fish9
-rw-r--r--functions/uz.fish3
11 files changed, 55 insertions, 64 deletions
diff --git a/functions/7za.fish b/functions/7za.fish
index f7c5d76..8a5dbac 100644
--- a/functions/7za.fish
+++ b/functions/7za.fish
@@ -5,7 +5,7 @@ if test (count $argv) -lt 1
return 1
end
-if not command -sq bsdtar
+if not check_install 'bsdtar' 'libarchive'
echo "Can't find bsdtar."
return 1
end
diff --git a/functions/alert.fish b/functions/alert.fish
index 6ab53cb..a21deac 100644
--- a/functions/alert.fish
+++ b/functions/alert.fish
@@ -1,22 +1,24 @@
function alert --description 'Report status of command to desktop'
- set -l cmd $argv
- set -l cmd_str (string join ' ' $cmd)
- set -l output (eval $cmd 2>&1)
- set -l retval $status
- if functions -q notify
- if test $retval -eq 0
- notify "✅ Done: $cmd_str" "$output"
- else
- notify "❌ Failed $cmd_str" "$output"
- end
+set -l cmd $argv
+set -l cmd_str (string join ' ' $cmd)
+set -l output (eval $cmd 2>&1)
+set -l retval $status
+
+if functions -q notify
+ if test $retval -eq 0
+ notify "✅ Done: $cmd_str" "$output"
+ else
+ notify "❌ Failed $cmd_str" "$output"
+ end
+else
+ if test $retval -eq 0
+ printf "✅ Done: %s\n%s\n" "$cmd_str" "$output"
else
- if test $retval -eq 0
- printf "✅ Done: %s\n%s\n" "$cmd_str" "$output"
- else
- printf "❌ Failed: %s\n%s\n" "$cmd_str" "$output"
- end
+ printf "❌ Failed: %s\n%s\n" "$cmd_str" "$output"
end
+end
+
+return $retval
- return $retval
end
diff --git a/functions/check_install.fish b/functions/check_install.fish
new file mode 100644
index 0000000..4c5da6c
--- /dev/null
+++ b/functions/check_install.fish
@@ -0,0 +1,27 @@
+function check_install -a tool -a package
+
+if test (count $argv) -lt 1
+ return 1
+end
+
+if command -sq $tool
+ return 0
+end
+
+if not ask "$tool doesn't seem to be installed. Attempt to install it?"
+ return 1
+end
+
+if test -z $package
+ set package $tool
+end
+
+pkgadd $package || return 1
+
+if not command -sq $tool
+ return 1
+end
+
+return 0
+
+end
diff --git a/functions/lscmd.fish b/functions/lscmd.fish
index d59974d..0c9c34a 100644
--- a/functions/lscmd.fish
+++ b/functions/lscmd.fish
@@ -2,7 +2,7 @@ function lscmd --description "Show installed useful command line tools"
set progsfile "$__fish_config_dir/progs.csv"
-if not command -sq 'textql'
+if not check_install 'textql'
echo "Can't find textql."
return 1
end
diff --git a/functions/rchmod.fish b/functions/rchmod.fish
index 63f64f0..70ddbc4 100644
--- a/functions/rchmod.fish
+++ b/functions/rchmod.fish
@@ -1,10 +1,5 @@
function rchmod --description 'Recursively reset perms of files and folders' -a dmode -a fmode
-if not command -sq 'find'
- echo "Can't find find."
- return 1
-end
-
if test -z $dmode
set dmode '0755'
end
diff --git a/functions/renlow.fish b/functions/renlow.fish
index 98b0e4c..1581550 100644
--- a/functions/renlow.fish
+++ b/functions/renlow.fish
@@ -1,10 +1,5 @@
function renlow --description 'Rename all files and directories with lowercase characters'
-if not command -sq 'find'
- echo "Can't find find."
- return 1
-end
-
for file in (find . -type f)
set -l element (string split -r -m1 / $file)
mv $file $element[1]/(string lower $element[2])
diff --git a/functions/rlsxattr.fish b/functions/rlsxattr.fish
index 0e71e49..e52d820 100644
--- a/functions/rlsxattr.fish
+++ b/functions/rlsxattr.fish
@@ -1,20 +1,10 @@
function rlsxattr --description 'Recursively list all files with xattrs'
-if not command -sq 'getfattr'
+if not check_install 'getfattr' 'attr'
echo "Can't find getfattr."
return 1
end
-if not command -sq 'sed'
- echo "Can't find sed."
- return 1
-end
-
-if not command -sq 'awk'
- echo "Can't find awk."
- return 1
-end
-
-getfattr -R -h -d . 2>/dev/null | grep '^# file:' | sed 's/^# file: //'
+command getfattr -R -h -d . 2>/dev/null | grep '^# file:' | sed 's/^# file: //'
end
diff --git a/functions/rsdos.fish b/functions/rsdos.fish
index 6efec55..eabe440 100644
--- a/functions/rsdos.fish
+++ b/functions/rsdos.fish
@@ -1,17 +1,10 @@
function rsdos --description 'Recursively delete all user.DOSATTRIB xattrs'
-if not command -sq 'find'
- echo "Can't find find."
- return 1
-end
-
-if not command -sq 'setfattr'
+if not check_install 'setfattr' 'attr'
echo "Can't find setfattr."
return 1
end
-find . -exec setfattr -x user.DOSATTRIB {} + 2>/dev/null
-
-return 0
+command find . -exec setfattr -x user.DOSATTRIB {} + 2>/dev/null
end
diff --git a/functions/rsmac.fish b/functions/rsmac.fish
index f0d3e49..826f7dc 100644
--- a/functions/rsmac.fish
+++ b/functions/rsmac.fish
@@ -1,10 +1,5 @@
function rsmac --description 'Recursively delete all .DS_Store files'
-if not command -sq 'find'
- echo "Can't find find."
- return 1
-end
-
-find . -type f -name '.DS_Store' -delete
+command find . -type f -name '.DS_Store' -delete
end
diff --git a/functions/rsxattr.fish b/functions/rsxattr.fish
index 7003879..bd1456e 100644
--- a/functions/rsxattr.fish
+++ b/functions/rsxattr.fish
@@ -1,16 +1,11 @@
function rsxattr --description 'Recursively delete all user xattrs'
-if not command -sq 'getfattr'; and command -sq 'setfattr'
+if not check_install 'getfattr' 'attr'
echo "Can't find xattr tools."
return 1
end
-if not command -sq 'sed'
- echo "Can't find sed."
- return 1
-end
-
-if not command -sq 'awk'
+if not check_install 'awk' 'gawk'
echo "Can't find awk."
return 1
end
diff --git a/functions/uz.fish b/functions/uz.fish
index b23780f..1611157 100644
--- a/functions/uz.fish
+++ b/functions/uz.fish
@@ -5,7 +5,7 @@ if test (count $argv) -lt 1
return 1
end
-if not command -sq bsdtar
+if not check_install 'bsdtar' 'libarchive'
echo "Can't fint bsdtar."
return 1
end
@@ -23,4 +23,3 @@ for archive in $argv
end
end
-