commit 48bb2a24ba0c2fd967e4e4178a614d5c8ce6e448
parent cbc784462fe4c161f5b9e980fe290325c951067b
Author: Rikard Karlsen <rk@reen.com>
Date: Sat, 21 May 2022 12:18:31 +0200
cleanup and documentation
Diffstat:
5 files changed, 71 insertions(+), 20 deletions(-)
diff --git a/addscript b/addscript
@@ -1,13 +1,26 @@
#!/bin/sh
-[ "$1" = "" ] && echo "Need name of script" && exit 1
+# Configuration
+[ -n "$BIN_HOME" ] \
+ && dir="$BIN_HOME" \
+ || dir="$HOME/.local/bin"
-_filename="$HOME/.local/bin/$1"
+usage() {
+ echo "addscript -- create boilerplate executable file and edit"
+ echo
+ echo "Usage: addscript NAME"
+ exit 1
+}
-[ -f "$_filename" ] && nvim "$_filename" && exit
+[ -z "$1" ] || [ "$1" = "-h" ] && usage
-touch "$_filename"
-chmod +x "$_filename"
-echo "#!/bin/sh\n\n" > "$_filename"
-nvim "$_filename"
+filename="$dir/$1"
+
+# File already exists
+[ -f "$filename" ] && $EDITOR "$filename" && exit
+
+# File does not exist
+echo "#!/bin/sh\n\n" > "$filename"
+chmod +x "$filename"
+$EDITOR "$filename"
diff --git a/crypto b/crypto
@@ -1,10 +1,32 @@
#! /bin/sh
+# Written in a FORTH-like manner. Experimentally.
+
+usage() {
+ echo "crypto -- calculates value of your crypto portfolio with rate.sx"
+ echo
+ echo "USAGE"
+ echo "\t\$XDG_CONFIG_HOME/cryptorc should be an executable file that is"
+ echo "\tsetting the following enviromental variables:"
+ echo
+ echo "\t* currency: the currency you want to show the result in."
+ echo "\t* amount: the crypto values, separated by \"+\", as it is"
+ echo "\t the format rate.sx accepts."
+ echo
+ echo "EXAMPLE CRYPTORC"
+ echo "\t#!/bin/sh"
+ echo "\tcurrency=\"eur\""
+ echo "\tamount=\"0.55btc+11eth\""
+ exit 1
+}
+
+[ "$1" = "-h" ] && usage
+
_configfile="$XDG_CONFIG_HOME/cryptorc"
alias config_not_exists\?="[ ! -x $_configfile ]"
alias source_config=". $_configfile"
-alias exit_with_error="echo 'ERROR: Config file nonexistent or not executable.' && exit"
+alias exit_with_error="echo 'Error: config file nonexistent or not executable' && exit"
config_not_exists? && exit_with_error || source_config
diff --git a/discotime b/discotime
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
mpv "https://www.youtube.com/playlist?list=PL8RuAUpRy-Eo6N1zMN196VofrLJTG4XmJ" \
--no-video \
diff --git a/diskspace-usage b/diskspace-usage
@@ -1,3 +1,4 @@
-#! /bin/sh
+#!/bin/sh
+
du -hd1 -BM "$1" | sort -hr
diff --git a/dugrep b/dugrep
@@ -1,22 +1,37 @@
#!/bin/sh
-# Find all files with the .$1 extention, lets you choose one, then exec with $2.
+# Configuration
+#theme="-theme sidebar"
+selector="rofi -width 75% -dmenu -i $theme -p :"
+
+usage() {
+ echo "dugrep -- finds all files with the .\$1 extention"
+ echo " lets you choose one, then exec with \$2."
+ echo
+ echo "USAGE"
+ echo "\tdugrep EXT EXE [-]"
+ echo
+ echo "\tUse \"-\" to open EXE in a new terminal."
+ exit 1
+}
+
+[ -z "$1" ] || [ -z "$2" ] || [ "$1" = "-h" ] \
+ && usage
-# theme="-theme sidebar"
-theme=""
-_filter_files() {
- for ext in $(echo $1 | tr "," "\n"); do
+filter_files() {
+ for ext in $(echo "$1" | tr "," "\n"); do
du -a $HOME --exclude=".*" | cut -f2 | grep "\.$ext$"
done
}
-file=`_filter_files "$1" | sort | rofi -width 75% -dmenu -i $theme -p :`
+file=$(filter_files "$1" | sort | $selector)
+[ -z "$file" ] && exit
-[ "$file" = "" ] && exit
+[ "$3" = "-" ] \
+ && $TERMINAL -e "$2 \"$file\"" && exit
-[ "$2" = "$EDITOR" ] && [ "$3" = "-" ] && $TERMINAL -e "$EDITOR \"$file\"" && exit
-
-"$2" "$file"
+$2 "$file"
#xargs -r -d "\n" "$2"
+