diff --git a/Bashrc.wiki b/Bashrc.wiki index 0c2f931..24a6de7 100644 --- a/Bashrc.wiki +++ b/Bashrc.wiki @@ -101,3 +101,140 @@ getdst() { }}} As an added bonus, the `-l` option will print the url for that product's support page. + +---- + +==Screenshot== + +This function wraps `maim(1)` and `fb(1)` to simplify my most used options. It uses maim to capture either the full screen, the active window, or a mouse selection to a file, or directly to a pastebin. + +{{{class="prettyprint" +# Screenshot utils +shot() { + # Usage: shot XY + local destdir="$HOME/Pictures/screenshots" + local fname="shot-$(date +%F-%T).png" + local pb="fb" + local paste msgt msgd opts + + if [ -z "$1" ]; then + printf "Usage: shot XY +X: Target +Y: Destination + +Valid Targets: +w Active Window +a All displays +s Mouse Selection + +Valid Destinations: +f Save to file (defined in function) +p Upload to a pastebin (defined in function) +" + return + fi + + # X: What to capture + case ${1:0:1} in + # Active window + w) printf "Focus target window now...\n" + opts="-i $(xdotool getactivewindow)" + msgt="active window" + ;; + # All + a) msgt="all displays" + ;; + # Mouse selection + s) opts="-s --noopengl" + msgt="mouse selection" + ;; + + *) printf "Unknown target: %s\n" "${1:0:1}" + return + ;; + esac + + #Y: Where to put the result + case ${1:1:1} in + # Save to file + f) msgd="file: $destdir/$fname" + ;; + # Post to a pastebin + p) destdir=$destdir/pasted + msgd="pastebin" + paste=1;; + + *) printf "Unknown destination: %s\n" "${1:1:1}" + return + ;; + esac + + # Make sure destination directory will exist + [[ ! -d "$destdir" ]] && mkdir -p "$destdir" + local fpath="${destdir}/${fname}" + # If target is active window, give a 5 second countdown before running maim + [[ "$msgt" = "active window" ]] && countdown 5 + + maim $opts "$fpath" + printf "Captured %s -> %s\n" "$msgt" "$msgd" + # If destination is a pastebin, do the needful + [[ "$paste" ]] && $pb "$fpath" +} +}}} + +This probably isn't the most robust solution, but it works pretty well. Patches welcome. + + +---- + +==Countdown== + +Found this little function when I wanted to add functionality to `shot()`. It takes an integer as an argument, then counts down that number of seconds visually. + +{{{class="prettyprint" +countdown() { + local secs="$1" + while [ $secs -gt 0 ]; do + echo -ne "$secs\033[0K\r" + sleep 1 + : $((secs--)) + done +} +}}} + +This probably isn't the sanest or safest solution to the problem, but it gets the job done. Patches welcome. + +---- + +==FontFind== + +Sometimes you just need to figure out what font provides a specific character. This function provides that solution: + +{{{class="prettyprint" +fontfind() { + if [[ -z $1 || ${#1} -gt 1 ]]; then + printf "E: only one character accepted" + fi + local glyph=$1 + FC_DEBUG=4 pango-view -qt "$glyph" 2>&1 | awk -F \" '/family: / { m = $2 } END { print m }' +} +}}} + +---- + +==Vactivate== + +I started needing more than one python virtualenv, and I wanted easy access to my own specific file structure. Additionally, I wanted the ability to deactivate the venv like I would exit a child shell. This is the solution that I came up with: + +{{{class="prettyprint" +vactivate() { + local path=~/.venv/$1 + + if [[ ! -d $path ]]; then + python -m venv $path --prompt "venv: $1" + fi + source $path/bin/activate; bash; deactivate +} +}}} + +A caveat to this is that the prompt modification that venv usually applies is not available using this method. If a prompt modification is desired, it needs to be taken care of elsewhere.