: bharatvaj/dotfiles

Cross platform dotfiles for linux, mac and windows

commit 10402af6d7df81364db9dc0d8fd876e3e8e28a6a
parent 6375cdc111c2b5c95f88a2aa47164b3d8ab445b6
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Tue, 14 Apr 2026 08:10:41 +0530

extract.sh: Add support for .exe

extract.sh: Fix shellhceck errors

sh: Remove thwart in favor of multimap

sh: Support file and directory checking in 'there'
4 files changed, 31 insertions(+), 31 deletions(-)
M
.config/profile.cmd
|
6
+++---
M
.config/sh/aliases
|
12
++++--------
M
.config/sh/functions
|
35
+++++++++++++++++++----------------
M
.local/bin/sh/extract.sh
|
9
+++++----
diff --git a/.config/profile.cmd b/.config/profile.cmd
@@ -9,7 +9,7 @@ doskey undot=rmdir "%XDG_HOME%\.git"
 
 doskey e=%EDITOR% $*
 doskey g=git $*
-doskey hb=sh %USERPROFILE%\.local\bin\sh\hb $*
+doskey hb=sh "%XDG_HOME%\.local\bin\sh\hb" $*
 doskey l=vifm .
 doskey ls=dir /B $*
 doskey m=make $*

@@ -17,12 +17,12 @@ doskey n=cd $*
 doskey open=start $*
 doskey pwd=cd
 doskey rm=del $*
-doskey x=7z x $*
+doskey x=sh "%XDG_HOME%\.local\bin\sh\extract.sh" $*
 doskey killall=taskkill /f /im $*
 doskey ?=lynx -cfg "%XDG_CONFIG_HOME%\lynx\lynx.cfg" $*
 
 rem FIXME This has the draw back that, if scripts are launched in %WINDIR%\System32,
-rem like "Open command prompt" or make, it will just cd into %USERPROFILE%
+rem like "Open command prompt" or in any way, it will just cd into %USERPROFILE%
 IF /I "%CD%"=="%WINDIR%\System32" (cd /D "%USERPROFILE%")
 
 set FM=vifm
diff --git a/.config/sh/aliases b/.config/sh/aliases
@@ -6,14 +6,10 @@ alias wget='wget --hsts-file="$XDG_CACHE_HOME/wget-hsts"'
 
 # [misc]
 # alias doas=sudo
-alias qc="ssh \"\$(sed -n -e '/\*.*/d' -e '/^Host/s/^Host //p' $XDG_HOME/.ssh/config | $FUZZER)\""
-
-# [helper_functions]
-cd_and_ls() { cd $* && ls; }
-thwart() { for t in $*; do there $t || alias $t="sl '$t'"; done }
-
-# [baseutils_conditioning]
-thwart lls sls lsl lss kls cdd mr
+# ssh workflow
+alias qc="there \"$XDG_HOME/.ssh/config\" && ssh \"\$(sed -n -e '/\*.*/d' -e '/^Host/s/^Host //p' \"$XDG_HOME/.ssh/*config\" | $FUZZER)\""
+# thwart - baseutils_conditioning
+multimap sl lls sls lsl lss kls cdd mr
 
 # [ip]
 # TODO make this cross-platform
diff --git a/.config/sh/functions b/.config/sh/functions
@@ -1,20 +1,18 @@
+# helper functions
+
 [ -n "$BASH" ] && is_bash=-f
 
 there() {
 	# Checks the availability of an executable
-	command -v "$@" >/dev/null 2>&1
+	if ! command -v "$@" >/dev/null; then
+		for f in "$@"; do
+			test -f "$f" || test -d "$f" || return 1
+		done
+	fi
 } && export $is_bash there
 
 open_project() {
 	# search only dirs
-	search_loc=${1:-.}/*
-	for i in $search_loc/.git/ $search_loc/*/.git/; do
-		echo "$i.."
-	done
-} && export $is_bash open_project
-
-open_project() {
-	# search only dirs
 	search_loc=${1:-.}
 	cd "$search_loc" || return
 	gdir="$(find . -maxdepth 2 -type d -name .git | sed 's/.git$//' | $FUZZER)"

@@ -77,11 +75,16 @@ download() {
 }
 
 tpm() {
-		case "$1" in
-			copy) shift; tpm-copy "$@" ;;
-			generate) shift; tpm-generate "$@" ;;
-			otp) shift; tpm-otp "$@" ;;
-			ls) tpm-ls ;;
-			*) command tpm "$@" ;;
-		esac
+	case "$1" in
+		copy) shift; tpm-copy "$@" ;;
+		generate) shift; tpm-generate "$@" ;;
+		otp) shift; tpm-otp "$@" ;;
+		ls) tpm-ls ;;
+		*) command tpm "$@" ;;
+	esac
 }
+
+cd_and_ls() { cd $* && ls; }
+
+multimap() { c=$1; shift; for t in $*; do there $t || alias $t="$c '$t'"; done }
+
diff --git a/.local/bin/sh/extract.sh b/.local/bin/sh/extract.sh
@@ -4,14 +4,15 @@
 # Iterate over each arguments
 # Treat last argument as dest folder? or use -d
 # Allow extraction of multple archives in the order
-test $# -lt 1 && { printf "Usage: $(basename $0) <archive>\n"; exit 1; }
-test -f "$1" || { printf "$0: $1: No such file \n"; exit 1; }
+test $# -lt 1 && { echo "Usage: extract.sh <archive>"; exit 1; }
+test -f "$1" || { printf "%s: %s: No such file \n" "$0" "$1"; exit 1; }
 case "$1" in
     *.a) ar x "$1" ;;
     *.z) 7z x "$1" ;;
     *.rar) unrar x "$1" ;;
     *.tar|*.tar.xz|*.tar.gz) tar -xvf "$1" ;;
     *.tar.bz2) tar -xzvf "$1" ;;
+    *.exe) lessmsi x "$1" ;;
     *.bz2) bzip2 -d "$1" ;;
     *.bz) bzip2 -d "$1" ;;
     *.gz) gunzip -d "$1" ;;

@@ -19,8 +20,8 @@ case "$1" in
     *.zip) unzip "$1" ;;
     *.mp4)
         audio_codec=$(ffprobe -show_streams -select_streams a "$1" | grep codec_name | cut -f2 -d "=")
-        ffmpeg -i "$1" -c:a copy $(basename $1).${audio_codec}
+        ffmpeg -i "$1" -c:a copy "$(basename "$1").${audio_codec}"
         ;;
 
-*) printf "'$1' Error. Unsupported filetype.\n" >&2 ;;
+*) echo "'$1' Error. Unsupported filetype." >&2 ;;
 esac