From afdb845fd1f29cb6493cda003d35e3da371b70f4 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 29 Jul 2021 16:02:20 +0200 Subject: [PATCH] bin: document scripts --- .local/bin/scripts/b | 1 + .local/bin/scripts/cj | 1 + .local/bin/scripts/dif | 2 +- .local/bin/scripts/edit | 2 +- .local/bin/scripts/ex | 2 +- .local/bin/scripts/favicon | 1 + .local/bin/scripts/focus | 1 + .local/bin/scripts/grepman | 1 + .local/bin/scripts/help | 1 + .local/bin/scripts/launch | 1 + .local/bin/scripts/log | 10 ---------- .local/bin/scripts/setupScreens | 1 + .local/bin/scripts/walli | 4 ++++ .local/bin/scripts/x | 2 -- README.org | 10 +++++++++- 15 files changed, 24 insertions(+), 16 deletions(-) delete mode 100755 .local/bin/scripts/log delete mode 100755 .local/bin/scripts/x diff --git a/.local/bin/scripts/b b/.local/bin/scripts/b index 152cf03..e4f3130 100755 --- a/.local/bin/scripts/b +++ b/.local/bin/scripts/b @@ -1,4 +1,5 @@ #!/bin/sh +# [b]rowse - custom ls or bat depending on file type # Show type & contents of given files or PWD set -eo pipefail diff --git a/.local/bin/scripts/cj b/.local/bin/scripts/cj index 4a28440..350813d 100755 --- a/.local/bin/scripts/cj +++ b/.local/bin/scripts/cj @@ -1,2 +1,3 @@ #!/bin/sh +# [c]at the given files as prettified [j]son cat "$@" | while read -r line; do echo -n "$line" | python -m json.tool 2>/dev/null; done | bat --language json --style numbers diff --git a/.local/bin/scripts/dif b/.local/bin/scripts/dif index 5f0910f..bbd39bc 100755 --- a/.local/bin/scripts/dif +++ b/.local/bin/scripts/dif @@ -1,5 +1,5 @@ #!/bin/sh +# interactive diff with pagination and nice coloring set -o pipefail -# interactive diff with pagination diff-color --report-identical-files "$@" | less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen diff --git a/.local/bin/scripts/edit b/.local/bin/scripts/edit index f27aa2c..1d613f5 100755 --- a/.local/bin/scripts/edit +++ b/.local/bin/scripts/edit @@ -1,5 +1,5 @@ #!/bin/sh - +# Edit a file with appropriate rights, creating parent directories if necessary test ! -f "$1" && ( mkdir -p $(dirname "$1") || sudo mkdir -p $(dirname "$1") ) echo "Editing $1..." if test -w "$1" || (test ! -f "$1" && test -w $(dirname "$1")) diff --git a/.local/bin/scripts/ex b/.local/bin/scripts/ex index 35f4657..ec68787 100755 --- a/.local/bin/scripts/ex +++ b/.local/bin/scripts/ex @@ -17,7 +17,7 @@ for arg do *.7z) 7z x "$arg" ;; *.deb) ar x "$arg" ;; *.tar.xz) tar xf "$arg" ;; - *.zst) unzstd "$arg" ;; + *.zst) unzstd "$arg" ;; *) echo "'$arg' cannot be extracted by ex" ;; esac else diff --git a/.local/bin/scripts/favicon b/.local/bin/scripts/favicon index 7bd6c37..2bb92af 100755 --- a/.local/bin/scripts/favicon +++ b/.local/bin/scripts/favicon @@ -1,3 +1,4 @@ #!/bin/bash +# Extract the icon of a given page using duckduckgo read -p URL? url xdg-open "https://icons.duckduckgo.com/ip2/$url.ico" diff --git a/.local/bin/scripts/focus b/.local/bin/scripts/focus index 7a1361c..54d34d7 100755 --- a/.local/bin/scripts/focus +++ b/.local/bin/scripts/focus @@ -1,3 +1,4 @@ +# launch my focus playlist playlistPath="$MUSIC/Playlists" test -z "$1" && vp "$playlistPath/focus.m3u8" || (find -L $playlistPath -iname "focus-$1.m3u8" -print0 | grep --null-data . || diff --git a/.local/bin/scripts/grepman b/.local/bin/scripts/grepman index 1fee258..e861820 100755 --- a/.local/bin/scripts/grepman +++ b/.local/bin/scripts/grepman @@ -1,2 +1,3 @@ #!/bin/sh +# Grep through all manuals find /usr/share/man -name "*$1*" | xargs gunzip -c | grep $2 --color=auto diff --git a/.local/bin/scripts/help b/.local/bin/scripts/help index ef85f50..d449a71 100755 --- a/.local/bin/scripts/help +++ b/.local/bin/scripts/help @@ -1,4 +1,5 @@ #!/bin/sh +# open info-page, man-page or buffered help flag case $1 in (vlc) unbuffer vlc --full-help "${@:2}" | ${PAGER:-less} --quit-if-one-screen;; (zsh|zmv) # https://unix.stackexchange.com/questions/19290/zmv-for-zsh-dry-runs-and-man-pages diff --git a/.local/bin/scripts/launch b/.local/bin/scripts/launch index 7e25bce..5171ce2 100755 --- a/.local/bin/scripts/launch +++ b/.local/bin/scripts/launch @@ -1,4 +1,5 @@ #!/bin/sh +# Run a program in the background if it is not running already #ps aux | grep -v $0 | grep -m 1 $1 echo -n "$1: " pgrep ${2:-$1} -a | grep --color=never -m 1 . || ( echo Launching && ($1 >/dev/null 2>&1 &) ) diff --git a/.local/bin/scripts/log b/.local/bin/scripts/log deleted file mode 100755 index 1de6411..0000000 --- a/.local/bin/scripts/log +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -local date_args=${LOG_TIME_DEFAULT:-d} - -case $1 in - (y) - (m) - (d) - (h) - (t) -esac diff --git a/.local/bin/scripts/setupScreens b/.local/bin/scripts/setupScreens index d4431b0..fc72c28 100755 --- a/.local/bin/scripts/setupScreens +++ b/.local/bin/scripts/setupScreens @@ -1,3 +1,4 @@ +# Reconfigure two side-by-side 4k and FHD displays via xrandr k4=$(xrandr | grep -1 ' 3840' | grep ' connected ' | cut -d' ' -f1) k2=$(xrandr | grep -1 ' 1920' | grep ' connected ' | cut -d' ' -f1) diff --git a/.local/bin/scripts/walli b/.local/bin/scripts/walli index 1db88be..e47049d 100755 --- a/.local/bin/scripts/walli +++ b/.local/bin/scripts/walli @@ -1,4 +1,8 @@ #!/bin/sh +# Blocks internet at night using iptables and enables it only upon request +# Migration to nftables is outstanding + +# Auto-elevate test "$EUID" -eq 0 || exec sudo "$0" "$@" set -e diff --git a/.local/bin/scripts/x b/.local/bin/scripts/x deleted file mode 100755 index 4591a62..0000000 --- a/.local/bin/scripts/x +++ /dev/null @@ -1,2 +0,0 @@ -startx -# sudo /usr/bin/prime-switch diff --git a/README.org b/README.org index 9c25328..1cf509e 100644 --- a/README.org +++ b/README.org @@ -2,6 +2,13 @@ I mainly use Arch Linux, currently with the KDE desktop environment with the intention to move to Awesome soon. + +If you are looking to snag some of my handy tools, +focus on =.local/bin/scripts= and =.config/shell=. +Among daily use are ~b~, ~edbin~, ~edconf~, ~edit~, ~yas~, ~walli~ +and [[https://github.com/ajeetdsouza/zoxide][zoxide]]-based ~d~/~di~ which in turn use ~zfz~, ~zf~ & ~locz~. + +~ex~, ~help~, ~moul~, ~mvk~, ~rpl~, ~s~, ~sd~, ~tl~ are also commonly used conveniences. ** Root I am trying to keep my home clean, but some files unfortunately cannot be moved. @@ -10,7 +17,8 @@ it contains lots of mappings to store files according to XDG and configuration for ~less~ and ~fzf~. ** .config - [[.config/shell][shell]] :: shell aliases & functions grouped into a few different areas, focused on zsh but mostly usable with bash -- doom :: [[https://github.com/hlissner/doom-emacs][Doom Emacs]] configuration with personalized snippets +- [[.config/zsh][zsh]] :: zsh plugin configuration & custom completions +- [[.config/doom][doom]] :: [[https://github.com/hlissner/doom-emacs][Doom Emacs]] configuration with personalized snippets - ideavim, vifm, nvim :: vi-related tools - git, yadm :: version control ** .local