summaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/desktop/setbg (renamed from .local/bin/setbg)0
-rwxr-xr-x.local/bin/development/dev67
-rwxr-xr-x.local/bin/development/go-module-rename8
-rwxr-xr-x.local/bin/fgrp5
-rwxr-xr-x.local/bin/fmd17
-rwxr-xr-x.local/bin/open4
6 files changed, 65 insertions, 36 deletions
diff --git a/.local/bin/setbg b/.local/bin/desktop/setbg
index c288895..c288895 100755
--- a/.local/bin/setbg
+++ b/.local/bin/desktop/setbg
diff --git a/.local/bin/development/dev b/.local/bin/development/dev
index cd95f27..37b50d6 100755
--- a/.local/bin/development/dev
+++ b/.local/bin/development/dev
@@ -3,24 +3,26 @@
err() { [ "$DEV_SUPRESS_ERRORS" = 1 ] ||
printf "dev: %s\n" "$@" >&2; exit 5; }
-[ "$#" -lt 2 ] && { err "dev - execute action based on file
-USAGE: dev <ACTION> <FILE> [ARGS...]"; }
+[ "$#" -lt 2 ] && { err "dev - execute task based on file
+USAGE: dev <TASK> <FILE> [ARGS...]"; }
-action="$1"
+task="$1"
file="$2"
-basename="${file##*/}"
+file_base="${file##*/}"
+file_ext="${file_base##*.}"
shift 2
[ -e "$file" ] || err "$file: No such file or directory"
# auxilary functions
findweb() { find "$@" -or -name '*.html'; }
+watchcmd() { entr -r sh -c "echo; date; printf '\n$ %s\n' '$1'; $1"; }
-### #################################################################
+#####################################################################
### BEGIN TASKS
-### #################################################################
+#####################################################################
sh_lint() { shellcheck -x "$file"; }
sh_run() { $(sed -n '1s|^#!/.*/\(.*\)|\1|p' "$file") "$file" "$@"; }
@@ -37,7 +39,11 @@ cls_compile() { file="${file%.cls}.tex"; tex_compile "$@"; }
html_format() { tidy -q "$file" 2>/dev/null; }
html_lint() { tidy -q "$file" >/dev/null; }
html_run() { w3m "$file"; }
+css_format() { esbuild "$file"; }
+css_minify() { esbuild --minify "$file"; }
js_test() { node "$file"; }
+js_format() { esbuild "$file"; }
+js_minify() { esbuild --minify "$file"; }
json_format() { jq . "$file"; }
php_run() { php "$file" "$@"; }
@@ -50,7 +56,7 @@ go_lint() { gofmt -d "$file"; }
go_compile() { go build "$file"; }
go_run() { "$(realpath "${file%.go}")" "$@"; }
go_test() { TMPDIR=~/.cache/go-tmp go run "$file" "$@"; }
-go_serve() { findweb . -name '*.go' | entr -r sh -c "printf '\n\n$ go run *.go\n'; dev test *.go"; }
+go_serve() { findweb . -name '*.go' | watchcmd "go run '$file'"; }
c_test() {
out="${file%.c}"
@@ -113,7 +119,6 @@ kt_test() {
py_format() { autopep8 "$file"; }
py_formatin() { autopep8 -i "$file"; }
-py_serve() { findweb . -name '*.py' | entr -r python "$file"; }
# py_lint() {
# [ -t 1 ] && printf '\033[33m'
# pycodestyle "$file" >&2
@@ -129,9 +134,23 @@ py_run() {
# fi
}
-### #################################################################
+## Default Tasks
+
+_serve() {
+ [ "$file_ext" != "$file_base" ] && FINDCMD="-name '*.$file_ext'"
+ eval "findweb -name '$file' $FINDCMD" | watchcmd "${@:-dev test $file}"
+}
+
+_build() {
+ if [ -f mimetype ]; then
+ [ "$(cat mimetype)" = "application/epub+zip" ] || return 5
+ zip -Xr9D "../${PWD##*/}.epub" mimetype *
+ fi
+}
+
+#####################################################################
### END TASKS
-### #################################################################
+#####################################################################
@@ -145,22 +164,24 @@ case $filetype in
application/json) filetype_ext="json" ;;
text/x-php) filetype_ext="php" ;;
text/x-awk) filetype_ext="awk" ;;
+ *) filetype_ext="NULL" ;;
esac
-if [ "${basename#*.}" != "${basename}" ]; then
- file_ext="${basename##*.}"
-else
- [ -z "$filetype_ext" ] && err "no file type association for $filetype"
+if [ "$file_ext" = "$file_base" ]; then
+ [ "$filetype_ext" = "NULL" ] && err "no file type association for $filetype"
NO_BASENAME=1
fi
execute_task() {
- file_task="${file_ext}_${action}"
- filetype_task="${filetype_ext}_${action}"
+ file_task="${file_ext}_${task}"
+ filetype_task="${filetype_ext}_${task}"
+ default_task="_${task}"
if [ "$NO_BASENAME" != 1 ] && [ "${tasks#*"[$file_task]"}" != "$tasks" ]; then
- $file_task; ret=$?
+ $file_task "$@"; ret=$?
elif [ "${tasks#*"[$filetype_task]"}" != "$tasks" ]; then
- $filetype_task; ret=$?
+ $filetype_task "$@"; ret=$?
+ elif [ "${tasks#*"[$default_task]"}" != "$tasks" ]; then
+ $default_task "$@"; ret=$?
else
return 1
fi
@@ -170,13 +191,13 @@ execute_task() {
tasks="$(sed -n "/^### BEGIN TASKS$/,/^### END TASKS$/ s/\(^[a-zA-Z0-9_]\+\)().*/[\1]/p" "$0")"
-if [ "$action" = test ]; then
- execute_task && exit
- for action in lint compile run; do
- execute_task && tested=1
+if [ "$task" = test ]; then
+ execute_task "$@" && exit
+ for task in lint compile run; do
+ execute_task "$@" && tested=1
done
[ "$tested" != 1 ] && err "no tests for .${file_ext:-$filetype_ext} file"
exit 0
fi
-execute_task || err "no $action action for .${file_ext:-$filetype_ext} file"
+execute_task "$@" || err "no $task task for .${file_ext:-$filetype_ext} file"
diff --git a/.local/bin/development/go-module-rename b/.local/bin/development/go-module-rename
new file mode 100755
index 0000000..68f158c
--- /dev/null
+++ b/.local/bin/development/go-module-rename
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# go-module-rename <OLD_MODULE_NAME> <NEW_MODULE_NAME>
+
+go mod edit -module "$2"
+find . -type f -name '*.go' | xargs sed -i \
+ -e "s|\"$1/|\"$2/|g" \
+ -e "s|\"$1\"|\"$2\"|g"
diff --git a/.local/bin/fgrp b/.local/bin/fgrp
index b9c0566..18bcabd 100755
--- a/.local/bin/fgrp
+++ b/.local/bin/fgrp
@@ -16,14 +16,15 @@ fi
mkdir -pv "$FZF_HISTDIR"
export FZF_HIST="$FZF_HISTDIR/grep_history"
-grep -Rnsi --exclude-dir=.git --exclude-dir=node_modules --color=always "$@" |
+cmd="grep -Rnsi --exclude-dir=.git --exclude-dir=node_modules --color=always"
+$cmd "$@" |
fzf --ansi \
--history="$FZF_HIST" \
--prompt="grep > " \
--preview='preview "$(echo {1} | cut -d: -f1)"' \
--preview-window="hidden" \
--bind 'ctrl-v:toggle-preview,ctrl-space:toggle-preview' \
- --bind "ctrl-r:reload(grep -Rns --color=always $*)" \
+ --bind "ctrl-r:reload($cmd $*)" \
--bind 'enter:execute(append-to-history {} "$FZF_HIST"; OPENFLAG=0 fgrp {})' \
--bind 'alt-e:execute(append-to-history {} "$FZF_HIST"; OPENFLAG=0 OPENWITH=${EDITOR:-vi} fgrp {})' \
--bind 'alt-o:execute(append-to-history {} "$FZF_HIST"; OPENFLAG=0 OPENWITH=${OPENER:-xdg-open} fgrp {})' \
diff --git a/.local/bin/fmd b/.local/bin/fmd
index 7dfb0e9..511b587 100755
--- a/.local/bin/fmd
+++ b/.local/bin/fmd
@@ -6,21 +6,20 @@
export PREVIEW="${PREVIEW:-"cat \"\$(dirname {})/.description/\${\$(basename {})%.*}.txt\" 2>/dev/null || preview {}"}"
-find_files() {
- filter="${XDG_CONFIG_HOME:-$HOME/.config}/ytignore"
- if command -v fd >/dev/null; then
- fd -I --color=always --type=file --ignore-file="$filter" . "$@"
- else
- eval "find $* -type f ! -path '*/.*' $(sed -z "s/\(\S\+\)\n/! -name '\1' /g" "$filter")"
- fi
-}
+filter="${XDG_CONFIG_HOME:-$HOME/.config}/ytignore"
+if command -v fd >/dev/null; then
+ export FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --ansi"
+ find_files() { fd -I --color=always --type=file --ignore-file="$filter" . "$@"; }
+else
+ find_files() { eval "find $* -type f ! -path '*/.*' $(sed -z "s/\(\S\+\)\n/! -name '\1' /g" "$filter")"; }
+fi
[ -z "$FZF_HISTDIR" ] &&
export FZF_HISTDIR="${XDG_STATE_HOME:-$HOME/.local/state}/fzf"
mkdir -pv "$FZF_HISTDIR"
export FZF_HIST="$FZF_HISTDIR/${FMD_HIST_NAME:-media_history}"
-find_files "$@" | sort | fzf --multi --reverse --history="$FZF_HIST" \
+find_files "$@" | fzf --multi --reverse --history="$FZF_HIST" \
--header="${FZF_HEADER:-Browse Media Files}" --header-first \
--preview="$PREVIEW" --preview-window=hidden \
--bind 'alt-C:execute(librewolf-open "$(mediainfo --inform="General;%Comment%" {})")' \
diff --git a/.local/bin/open b/.local/bin/open
index b054729..5b38cb7 100755
--- a/.local/bin/open
+++ b/.local/bin/open
@@ -5,7 +5,7 @@
for file in "$@"; do
case "$file" in
- *.pdf|*.djvu|*.epub) setsid -f zathura "$file" ;;
+ *.pdf|*.djvu|*.epub) setsid -f zathura "$file" 2>/dev/null ;;
*.png|*.jpg|*.jpeg|*.webp) setsid -f nsxiv "$file" ;;
*.gif|*.mkv|*.mp3|*.mp4|*.webm|*.ogg) ${PLAYER:-mpv --sub-auto=fuzzy} "$file" ;;
*.html) ${BROWSER:-w3m} "$file" ;;
@@ -25,7 +25,7 @@ for file in "$@"; do
case "$filetype" in
inode/directory) ${FILES:-lf} "$file" ; exit ;;
text/html*) ${BROWSER:-w3m} "$file" ;;
- *pdf|*djvu|*epub+zip|*oxps|*fictionbook) setsid -f zathura "$file" ;;
+ *pdf|*djvu|*epub+zip|*oxps|*fictionbook) setsid -f zathura "$file" 2>/dev/null ;;
text/*|*json|*zip|*zstd) "${EDITOR:-nvim}" "$file" ;;
application/vnd.openxmlformats-officedocument.*) setsid -f libreoffice "$file" ;;
application/sc) sc-im "$file" ;;