diff options
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/enter | 24 | ||||
| -rwxr-xr-x | bin/firefox | 1 | ||||
| -rwxr-xr-x | bin/fzfez | 103 | ||||
| -rwxr-xr-x | bin/grimshot | 2 | ||||
| -rwxr-xr-x | bin/lock | 33 | ||||
| -rwxr-xr-x | bin/menu | 6 | ||||
| -rwxr-xr-x | bin/mpvdiff | 3 | ||||
| -rwxr-xr-x | bin/oguri-cycle | 5 | ||||
| -rwxr-xr-x | bin/open | 32 | ||||
| -rwxr-xr-x | bin/semver | 29 | ||||
| -rwxr-xr-x | bin/swx | 4 | ||||
| -rwxr-xr-x | bin/trash | 29 | ||||
| -rwxr-xr-x | bin/vncez | 13 | ||||
| -rwxr-xr-x | bin/wfez | 75 | ||||
| -rwxr-xr-x | bin/xdg-exec | 23 |
15 files changed, 259 insertions, 123 deletions
diff --git a/bin/enter b/bin/enter index 61c1fb7..9c625a7 100755 --- a/bin/enter +++ b/bin/enter @@ -8,6 +8,7 @@ dockerfile="${PWD}/Dockerfile" priv= opts= become= +verbose= usage() { printf "usage: %s OPTIONS -- [ARGS]\n" "$(basename "$0")" @@ -18,12 +19,13 @@ usage() { printf " -o EXTRA OPTIONS\n" printf " -D (run with elevated privileged, but not privileged)\n" printf " -B (don't reassign uid/gid)\n" + printf " -v (be verbose)\n" printf "\n" printf "Enter the container defined in Dockerfile, with \$PWD mounted at /src\n" exit 2 } -while getopts t:i:f:o:BDh o; do +while getopts t:i:f:o:vBDh o; do case $o in t) target="$OPTARG" ;; i) img="$OPTARG" ;; @@ -31,12 +33,21 @@ while getopts t:i:f:o:BDh o; do o) opts="$OPTARG" ;; D) priv=1 ;; B) become=1 ;; + v) verbose=1 ;; h|?) usage ;; esac done shift $((OPTIND - 1)) -[ -z "$img" ] && img="$(basename "$(dirname "$(readlink -f -- "$dockerfile")")")" +if [ -z "$img" ]; then + img="$(basename "$(dirname "$(readlink -f -- "$dockerfile")")")" + + # allow setting this to some non-file value to skip building + # > enter -i alpine -f none + # for a quick alpine based container with $PWD mounted in + [ -f "$dockerfile" ] && \ + docker build --tag="$img" --target="$target" --file="$dockerfile" "$PWD" +fi extra_args= [ -n "$become" ] && extra_args="${extra_args} " @@ -58,17 +69,14 @@ extra_args= [ -n "$opts" ] && extra_args="${extra_args} ${opts}" -# allow setting this to some non-file value to skip building -# > enter -i alpine -f none -# for a quick alpine based container with $PWD mounted in -[ -f "$dockerfile" ] && \ - docker build --tag="$img" --target="$target" --file="$dockerfile" "$PWD" - [ -z "$become" ] && \ extra_args="${extra_args} --user="$(id -u):$(id -g)"" ep="sh" [ -n "$1" ] && { ep="$1"; shift; } + +[ -n "$verbose" ] && { set -x; } + exec docker run --rm -it \ --entrypoint="$ep" \ --mount=type=bind,src="$PWD",dst=/src -w /src $extra_args "$img" $@ diff --git a/bin/firefox b/bin/firefox index 659b854..ed3ddb9 100755 --- a/bin/firefox +++ b/bin/firefox @@ -6,6 +6,7 @@ bin=${FIREFOX_BIN:-firefox-nightly-bin} # enable touch device support export MOZ_USE_XINPUT2=1 +export MOZ_WEBRENDER=1 case "$(basename "$0")" in firefox|nightly) diff --git a/bin/fzfez b/bin/fzfez index dea63a1..dff86ba 100755 --- a/bin/fzfez +++ b/bin/fzfez @@ -6,40 +6,57 @@ if [ ! -f "$exec_hist" ]; then touch "$exec_hist" fi +_cat='cat' +if bat --version >/dev/null; then + _cat='bat --color=always --style=numbers,changes' +fi +_ls='ls' +if exa --version >/dev/null; then + _ls='exa --classify --group --header --group-directories-first --color=always' +fi + case "$1" in +help|-h|--help) + printf "usage: fzfez [exec|git-log|git-tag|git-branches|rg|fd|vimwiki|*]\n" + exit 1 ;; + exec) uniq "$exec_hist" \ | grep -v '^$' \ | fzf \ - --header 'Select or enter a command, {} is previous selection' \ + --header "${FZFEZ_HEADER:-EXEC:} select or enter a command, {} is \"${FZFEZ_EXEC_SELECTION}\"" \ --bind 'tab:replace-query' \ - --bind 'enter:print-query' \ - | tee -a $exec_hist \ + --bind 'esc:print-query' \ + --bind 'enter:replace-query+accept' \ + | tee -a $exec_hist >/dev/null \ | sed "s#{}#$2#g" \ - | sh -s + | sh -x -s exit $? ;; _preview) case "$(xdg-mime query filetype "$2")" in - inode/directory) exa -la "$2" ;; - text/*) head "$2" ;; - application/javascript) head "$2" ;; - application/x-shellscript) head "$2" ;; - application/json) jq "$2" ;; - application/x-compressed-tar) tar -tvf "$2" ;; - application/pdf) pdftotext "$2" - ;; - image/*) mediainfo "$2" ;; - video/*|audio/*) mediainfo "$2" ;; - *) file "$2" ;; + inode/directory) $_ls -la "$2" ;; + text/*) $_cat "$2" ;; + application/javascript) $_cat "$2" ;; + application/x-yaml) $_cat "$2" ;; + application/x-shellscript) $_cat "$2" ;; + application/json) jq "$2" || $_cat "$2" ;; + application/x-compressed-tar) tar -tvf "$2" ;; + application/pdf) pdftotext "$2" - ;; + image/*) mediainfo "$2" ;; + video/*|audio/*) mediainfo "$2" ;; + *) file "$2" ;; esac ;; -_preview2) # invoke mpv/imv for media files +_preview-detach) # invoke for media files case "$(xdg-mime query filetype "$2")" in - image/*) swx -f imv "$2" ;; - video/*|audio/*) swx -f mpv "$2" ;; - application/pdf) swx -f zathura "$2" ;; - *) $0 exec "$2" ;; + inode/directory) exa -la "$2" ;; + image/*) swx -f mvi "$2" ;; + video/*|audio/*) swx -f mpv "$2" ;; + application/pdf) swx -f zathura "$2" ;; + test/*) swx -t ${EDITOR} "$2" ;; + *) env FZFEZ_HEADER='PREVIEW-DETACH' $0 exec "$2" ;; esac ;; @@ -50,13 +67,12 @@ git-branches) | sed 's#^refs/##' \ | sed 's#^remotes/##' \ | sed 's#^heads/##' \ - | $0 \ + | env FZFEZ_HEADER='BRANCHES:' \ + $0 \ --ansi --no-sort --reverse --tac \ - --header 'Press ctrl-s to toggle sort' \ - --bind 'ctrl-s:toggle-sort' \ --preview 'git log --color=always --oneline --graph --date=short {} | head -${LINES}' \ --preview-window right:70% \ - --bind "ctrl-o:execute(git checkout {})" + --bind "ctrl-o:execute(git checkout {})+abort" ;; git-tags) @@ -66,7 +82,8 @@ git-tags) | sed 's#^refs/##' \ | sed 's#^remotes/##' \ | sed 's#^heads/##' \ - | $0 \ + | env FZFEZ_HEADER='TAGS:' \ + $0 \ --ansi --no-sort --reverse \ --preview 'git show --color=always {} | head -${LINES}' \ --preview-window right:70% @@ -74,7 +91,8 @@ git-tags) git-log) git log --color=always --oneline \ - | $0 \ + | env FZFEZ_HEADER='LOG:' \ + $0 \ --ansi --no-sort --reverse \ --preview 'echo {} | cut -d\ -f1 | xargs git show --color=always --pretty=full --stat --patch' \ --preview-window right:50% \ @@ -84,11 +102,10 @@ git-log) rg) shift - rg $@ --files-with-matches \ - | $0 \ - --header 'Press ctrl-s to toggle sort' \ - --bind 'ctrl-s:toggle-sort' \ - --preview "rg $* --color=always --no-filename --glob='{}' --context=5 --line-number" + rg --files-with-matches "$@" \ + | env FZFEZ_HEADER='RG:' \ + $0 \ + --preview "rg \"$*\" --color=always --no-filename --glob='{}' --context=5 --line-number" ;; vimwiki) @@ -96,26 +113,30 @@ vimwiki) fd -t f -e md "${1:-.*}" "$HOME/wiki" \ | sed "s#^$HOME/wiki/##" \ | sed 's#.md$##' \ - | $0 \ + | env FZFEZ_HEADER='VIMWIKI:' \ + $0 \ --print-query \ - --preview="cat -n $HOME/wiki/{}.md" \ + --preview="$_cat -n $HOME/wiki/{}.md" \ | xargs -r -i nvim +VimwikiIndex +VimwikiGoto\ {} ;; fd) shift - fd $@ \ - | $0 \ + fd "$@" \ + | env FZFEZ_HEADER='FD: c-o (xdg-open)' \ + $0 \ --ansi --reverse \ - --header 'Press ctrl-p to toggle preview, enter for xdg-open' \ - --bind 'ctrl-p:toggle-preview' \ - --bind "ctrl-space:execute($0 _preview2 {})" \ - --preview "$0 _preview {}" \ - --preview-window ':hidden' \ - | xargs -r xdg-open + --bind "ctrl-o:execute(xdg-open {})+abort" \ + --preview-window ':hidden' ;; *) fzf \ - --bind "ctrl-x:execute(${0} exec {})+accept" "$@" ;; + --header "${FZFEZ_HEADER:-FZF:} c-x (exec), ? (preview), c-space (preview-detach), c-s (sort)" \ + --preview "${0} _preview {}" \ + --preview-window ':hidden' \ + --bind '?:toggle-preview' \ + --bind 'ctrl-s:toggle-sort' \ + --bind "ctrl-space:execute(${0} _preview-detach {})" \ + --bind "ctrl-x:execute(env FZFEZ_HEADER=EXEC: FZFEZ_EXEC_SELECTION={} ${0} exec {})+accept" "$@" ;; esac diff --git a/bin/grimshot b/bin/grimshot index 434c97f..f661dad 100755 --- a/bin/grimshot +++ b/bin/grimshot @@ -134,11 +134,11 @@ elif [ "$ACTION" = "save" ] ; then if [ $? ]; then TITLE="Screenshot of $SUBJECT" MESSAGE=$(basename "$FILE") + wl-copy --type image/png < "$FILE" || die "Clipboard error" notifyOk "$MESSAGE" "$TITLE" else notifyError "Error taking screenshot with grim" fi - wl-copy --type image/png < "$FILE" || die "Clipboard error" elif [ "$ACTION" = "rec" ] ; then echo "$FILE" | awk '/png$/{exit 0}' && \ FILE=$(xdg-user-dir VIDEOS)/grimshot/$(now).mp4 diff --git a/bin/lock b/bin/lock index ecde789..41866a9 100755 --- a/bin/lock +++ b/bin/lock @@ -1,11 +1,28 @@ -#!/bin/sh +#!/bin/bash + +set -e +[ -n "$DEBUG" ] && set -x main_color="#4E4371" clear_color='#afd700' ver_color='#5f8787' wrong_color='#af005f' -exec swaylock -f \ +# --effect-compose '7.5%,93%;10%x-1;center;/home/robert/Pictures/gentoo-logo/gentoo-horizontal.png' +# --effect-compose '20%,50%;5%x-1;center;/home/robert/Pictures/hexagon.png' +# --effect-compose '30%,50%;10%x-1;center;/home/robert/Pictures/gentoo-logo/gentoo-logo.png' +if swaylock --help 2>&1 | grep effect >/dev/null; then + fx_args=( + --screenshots + --timestr '%H:%M' --datestr '%F' + --clock + --effect-scale 0.5 --effect-blur 10x5 --effect-scale 2 + --effect-vignette 0.6:0.3 + --effect-compose '49%,50%;20%x-1;center;/home/robert/.lock.png' + ) +fi + +exec swaylock -f ${fx_args[@]} \ --color=#000000EE \ --scaling=fill \ --font=Iosevka\ Sparkle \ @@ -26,14 +43,4 @@ exec swaylock -f \ --indicator-caps-lock \ --show-failed-attempts \ --hide-keyboard-layout \ - --indicator-idle-visible \ - --screenshots \ - --effect-scale 0.5 --effect-blur 10x5 --effect-scale 2 \ - --effect-vignette 0.6:0.3 \ - --effect-compose '49%,50%;20%x-1;center;/home/robert/.lock.png' \ - --clock \ - --timestr "%H:%M" --datestr "%F" - - # --effect-compose '7.5%,93%;10%x-1;center;/home/robert/Pictures/gentoo-logo/gentoo-horizontal.png' \ - # --effect-compose '20%,50%;5%x-1;center;/home/robert/Pictures/hexagon.png' \ - # --effect-compose '30%,50%;10%x-1;center;/home/robert/Pictures/gentoo-logo/gentoo-logo.png' \ + --indicator-idle-visible diff --git a/bin/menu b/bin/menu index 94d886b..82979d5 100755 --- a/bin/menu +++ b/bin/menu @@ -38,8 +38,12 @@ done passwd_arg= [ -n "${MENU_PASSWORD}" ] && passwd_arg=--password + +# make sure there we are the only running menu +pgrep "${arg0}" && pkill "${arg0}" + + # --monitor=1 \ exec "${arg0}" \ - --monitor=1 \ --no-overlap \ --ignorecase \ --list=10 \ diff --git a/bin/mpvdiff b/bin/mpvdiff index a218709..9d5ce4a 100755 --- a/bin/mpvdiff +++ b/bin/mpvdiff @@ -2,7 +2,8 @@ set -e [ -n "$DEBUG" ] && set -x -args="--title=mpvdiff --hwdec=v4l2m2m-copy" +# args="--title=mpvdiff --script=~~/scripts/diff" +args="--title=mpvdiff" if [ "$1" = "-h" ]; then printf "usage: %s [-2|-4] VIDEO..." "$(basename "$0")" diff --git a/bin/oguri-cycle b/bin/oguri-cycle index 495f983..30603a7 100755 --- a/bin/oguri-cycle +++ b/bin/oguri-cycle @@ -27,12 +27,14 @@ logger 'oguri-cycle: changing background(s)' || true OUTPUTS=( $(swq list output | jq -r '..|select(.transform?=="normal")|.name') ) BGS=( "$HOME/Pictures/animepics/__original_drawn_by_abisswalker8__222dc00159b116c4e8bb6366ab4b677e.png" -"$HOME/Pictures/animepics/__original_drawn_by_abisswalker8__c6069bdfad7b8f5d57dd1448ef2d85d9.png" "$HOME/Pictures/animepics/__original_drawn_by_n_bayashi__bf659af0c196a9fe8539be0f62205cca.jpg" "$HOME/Pictures/wallp/1514582672200.jpg" "$HOME/Pictures/wallp/1462298633114.jpg" "$HOME/Pictures/wallp/dahl_dresden_bei_mondlicht_1788.jpg" "$HOME/Pictures/wallp/1585191965174.jpg" +"$HOME/Pictures/animepics/__original_drawn_by_mita_mitauzo__a225b710fe369391a7cddcf58a614f8f.jpg" +"$HOME/Pictures/animepics/touhou drawn by cronstatd - 97bde9194d2a7b7cf1fbf9146a4f505f.jpg" +"$HOME/Pictures/animepics/original drawn by zhuang_yao - ff96be280475dd5098a76fc76c847b27.jpg" ) change_bg @@ -42,6 +44,7 @@ BGS=( "$HOME/Pictures/animepics/__original_and_1_more_drawn_by_poppo_sutchy__333475fc9dd799c33f85ca6e73c4e277.png" "$HOME/Pictures/animepics/__original_drawn_by_pei_sumurai__a7e972c537eab0898dcbd409f9854b0b.jpg" "$HOME/Pictures/animepics/__original_drawn_by_raruru__96312c6d44f35c66ac456428f1ef1c63.jpg" +"$HOME/Pictures/animepics/original drawn by karanagi - f016c50461614dfd2f3c19b3d7147051.jpg" ) change_bg --anchor=left diff --git a/bin/open b/bin/open index 9a1eb3f..ba809bf 100755 --- a/bin/open +++ b/bin/open @@ -20,39 +20,33 @@ shift $((OPTIND-1)) in="$1" -mime=$(file --mime-type $in | awk -F': ' '{print $2}' ) -ext=$(basename $in | rev | cut -d'.' -f1 | rev) +mime=$(file --mime-type "$in" | awk -F': ' '{print $2}' ) +ext=$(basename "$in" | rev | cut -d'.' -f1 | rev) opener=xdg-open fork() { - exec $@ 1>&2 2>/dev/null & + exec $@ >/dev/null 2>&1 & } - term() { fork alacritty --title="$1" --command "$@" } case $mime in - inode/directory) [ $termmode -eq 0 ] && vifm "$in" || fork nautilus -w "$in" ;; - # inode/file) fork nautilus -w $in ;; + inode/directory) [ $termmode -eq 0 ] && vifm "$in" ;; + inode/file) [ $termmode -eq 0 ] && vifm "$in" ;; - image/*) fork sxiv "$in" ;; - video/*) fork mpv --force-widow=yes "$in" ;; - audio/*) fork mpv --force-widow=yes "$in" ;; + image/*) fork mvi "$in" ;; + video/*) fork mpv --force-window=yes "$in" ;; + audio/*) fork mpv --force-window=yes "$in" ;; application/pdf) fork zathura "$in" ;; - application/vnd.ms-opentype|application/font-sfnt) - fork gnome-font-viewer "$in" ;; + # application/vnd.ms-opentype|application/font-sfnt) + # fork gnome-font-viewer "$in" ;; # now text... - text/*) - # echo $mime $ext - case $ext in - md|markdown) fork shiba "$(readlink -f "$in")" ;; - desktop) fork gtk-launch "$(basename "$in" | cut -d'.' -f1)" ;; - *) fork term nvim "$in" ;; - esac - ;; + text/md|text/markdown) + fork shiba "$(readlink -f "$in")" ;; + text/*) fork term ${EDITOR} "$in" ;; # everything else... *) exec $opener "$in" ;; diff --git a/bin/semver b/bin/semver index cdc993a..19d2a58 100755 --- a/bin/semver +++ b/bin/semver @@ -16,6 +16,8 @@ import getopt simple_tag = False force = False +changelog = True + def usage(): print(f"usage: {sys.argv[0]} OPTIONS COMMANDS") @@ -24,6 +26,7 @@ OPTIONS: \t-h\tshow this help \t-t\tonly create a simple tag, otherwise annotate as well \t-f\toverwrite existing tag +\t-c\tdon't write changelog COMMANDS: \tpatch @@ -34,16 +37,18 @@ COMMANDS: try: - opts, argv = getopt.getopt(sys.argv[1:], 'tfh') + opts, argv = getopt.getopt(sys.argv[1:], 'tfch') except getopt.GetoptError as err: print(err) usage() for o, val in opts: if o == "-t": - simple_tag = True + simple_tag = not force elif o == "-f": - force = True + force = not force + elif o == "-c": + changelog = not changelog elif o == "-h": usage() else: @@ -55,7 +60,8 @@ if subprocess.run(["git", "branch", "--show-current"], subprocess.run(["git", "pull", "--rebase"]) -p = subprocess.run(["git", "describe", "--abbrev=0", "--tags"], stdout=subprocess.PIPE) +p = subprocess.run(["git", "describe", "--abbrev=0", "--tags"], + stdout=subprocess.PIPE) describe = p.stdout.decode().strip() # TODO also ask to re-append the trailing portion.... e.g. -rev1 old_version = describe.split("-")[0].split(".") @@ -68,7 +74,9 @@ elif len(old_version) == 3: [major, minor, patch] = map(int, [major, minor, patch]) else: - print(f"WARNING: git describe returned invalid semver version: \"{describe}\"") + print( + f"WARNING: git describe returned invalid semver version: \"{describe}\"" + ) # sys.exit(1) # old_version = [0, 0, 0] @@ -125,5 +133,16 @@ else: args.extend([new_version]) subprocess.run(args) +if changelog: + import time + now = time.strftime("%Y-%m-%d", time.localtime()) + with open("CHANGELOG", "r+") as f: + data = f.read() + f.seek(0) + f.write(f"\n{new_version} ({now})\n\n") + f.write(shortlog) + f.write(data) + f.flush() + print(args) print(new_version) diff --git a/bin/swx b/bin/swx index dfe852f..284e5c7 100755 --- a/bin/swx +++ b/bin/swx @@ -123,7 +123,9 @@ if [ -n "${rotate}" ]; then fi if [ -n "${autotile}" ]; then - case "$(swq current workspace | jq -r '.layout')" in + layout=$(swq current con | jq -r '.layout') + # swq current workspace | jq -r '.. | select(.type?=="con" and .name?==null) | .layout' + case "${layout}" in split*) if [ "$(swq current con | jq '.rect | .width > .height')" = "true" ]; then swaymsg splith diff --git a/bin/trash b/bin/trash index 5b810c1..4a1de6e 100755 --- a/bin/trash +++ b/bin/trash @@ -1,5 +1,4 @@ #!/bin/sh - set -e TRASH="$HOME/.trash" @@ -34,20 +33,42 @@ yes | $0 --empty EOF } +ask() { + r=$(printf 'yes\nno\n' | MENU_PROMPT="delete $1" menu) + [ "${r}" = "yes" ] && return 0 + return 1 +} + +interactive=${TRASH_ASK:-} +trashrm=${TRASH_RM:-} + case "$1" in -e|--empty) empty_trash exit 0 ;; - -i|--install) + --install) install_auto_empty exit 0 ;; + -i) + interactive=1 + shift ;; -h|--help) echo "usage: trash [-e|--empty] FILE..." exit 1 ;; esac +set -x + # main -for f in "$@"; do +while test $# -gt 0; do + f="$1" ; shift + + [ -n "${interactive}" ] && { ask "$f" || continue; } + echo "+ $(basename "$f")" - mv "$f" "$TRASH/" + if [ -z "${trashrm}" ]; then + rm "$f" + else + mv "$f" "$TRASH/" + fi done diff --git a/bin/vncez b/bin/vncez index 068a199..f82f524 100755 --- a/bin/vncez +++ b/bin/vncez @@ -1,10 +1,11 @@ #!/bin/sh set -e +[ -n "$DEBUG" ] && set -x if [ -n "$1" ]; then printf "usage: %s\n" "$(basename "$0")" printf "\n" - printf "launches wayvnc(1), wshowkeys(1) and remmina(1)\n" + printf "launches a vnc server and client, creating a loopback X window\n" exit 2 fi @@ -13,16 +14,18 @@ if [ -n "$OUTPUT" ]; then server_args="-o ${OUTPUT}" fi -trap '{ printf "\n=> killing everything...\n"; pkill wayvnc; pkill gvncviewer; }' EXIT + +trap '{ printf "\n=> killing everything...\n"; }' INT +trap '{ killall -9 wayvnc gvncviewer; notify-send "stopped output mirror" "cleaned up viewer window and workspace"; }' EXIT # echo "=> starting wshowkeys" # swaymsg exec "wshowkeys -a bottom -a left -F 'Iosevka Sparkle 25' -t 1" >/dev/null echo "=> starting wayvnc" -swaymsg exec "wayvnc -c dmabuf -r ${server_args} 0.0.0.0" >/dev/null +swaymsg exec "wayvnc -r ${server_args} 0.0.0.0" echo "=> starting viewer" -swx -b none -S -F '1.0 tl' -- x11fy gvncviewer localhost +swx -w __vnc -- x11fy gvncviewer "0.0.0.0" -notify-send 'started screensharing' 'the vnc viewer window was moved to the scratchpad' +notify-send 'started output mirror' 'the vnc viewer X window was moved to new workspace\nyou can screen cast the desktop using it' while true; do sleep $((1024*1024)) done diff --git a/bin/wfez b/bin/wfez index 50f485d..eac1b55 100755 --- a/bin/wfez +++ b/bin/wfez @@ -2,37 +2,68 @@ set -e [ -n "$DEBUG" ] && set -x -if [ "$1" = "-h" ]; then - printf "usage: %s [FILE]\n" "$(basename "$0")" - printf "\n" - printf "Launches wf-recorder(1) with optimized settings.\n" - printf "If FILE is omitted, \$HOME/Videos/rec_TIMESTAMP.mkv is used.\n" - printf "Optionally environment vars can be used to tune things:\n" - printf " WF_AOUT - defaults to default pulseaudio sink\n" - printf " WF_AIN - defaults to default pulseaudio source\n" - printf " WF_AMUX - override creation of an pulseaudio sink for muxing\n" - printf " WF_VOUT - limit to output, defaults to focused output (swq current output)\n" - printf " WF_KEYS - launches wshowkeys(1)\n" - exit 2 -fi +# check requirements +for tool in wf-recorder wshowkeys pactl swq; do + if ! command -v "$tool" >/dev/null; then + printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2 + exit 1 + fi +done + + -output_file=${1:-"${HOME}/Videos/rec_$(now).mkv"} audio_output=${WF_AOUT} audio_input=${WF_AIN} video_output=${WF_VOUT} showkeys=${WF_KEYS} mux_sink=${WF_AMUX} +no_mux= + +while getopts i:o:m:v:kMh opt; do + case "$opt" in + i) # audio in + audio_input="${OPTARG}" ;; + o) # audio out + audio_output="${OPTARG}" ;; + m) # mux + mux_sink="${OPTARG}" ;; + v) # output to record + video_output="${OPTARG}" ;; + k) # showkeys + showkeys=1 ;; + M) # no mux + no_mux=1 ;; + h|?) + printf "usage: %s [-iomvkM] [FILE]\n" "$(basename "$0")" + printf "\n" + printf " Launches wf-recorder(1) with optimized settings.\n" + printf " When FILE is omitted, \$HOME/Videos/rec_TIMESTAMP.mkv is used.\n" + printf "\n" + printf " -o \t\taudio output; defaults to default pulseaudio sink\n" + printf " -i \t\taudio input; defaults to default pulseaudio source, can be 'none'\n" + printf " -m \t\taudio mux sink; override creation of an pulseaudio sink for muxing\n" + printf " -v \t\toutput to record; limit to output, defaults to focused output (swq current output)\n" + printf " -k \t\tlaunches wshowkeys(1)\n" + printf " -M \t\tdon't create a audio mux sink\n" + printf "\n" + exit 2 ;; + esac +done +shift $((OPTIND - 1)) -[ -z "${audio_output}" ] && audio_output=$(pacmd dump | grep "set-default-sink" | cut -d' ' -f2) -[ -z "${audio_input}" ] && audio_input=$(pacmd dump | grep "set-default-source" | cut -d' ' -f2) +output_file=${1:-"${HOME}/Videos/rec_$(now).mkv"} + +# setup defaults +[ -z "${audio_output}" ] && audio_output=$(pactl info | grep "Default Sink" | cut -d':' -f2 | xargs -L1) +[ -z "${audio_input}" ] && audio_input=$(pactl info | grep "Default Source" | cut -d':' -f2 | xargs -L1) [ -z "${video_output}" ] && video_output=$(swq current output) -if [ "${WF_AIN}" = "none" ] && [ -z "${WF_AMUX}" ]; then +if [ "${audio_input}" = "none" ] && [ -z "${mux_sink}" ]; then echo "mux: ${audio_output}" mux_sink="${audio_output}" fi -if [ -z "${mux_sink}" ]; then +if [ -z "${mux_sink}" ] && [ -z "${no_mux}" ]; then mux_sink=wf-mux mux_sink_id= output_loopback_id= @@ -40,7 +71,7 @@ if [ -z "${mux_sink}" ]; then prepare_mux_sink() { mux_sink_id=$(pactl load-module module-null-sink sink_name="${mux_sink}" channels=2) output_loopback_id=$(pactl load-module module-loopback sink="${mux_sink}" source="${audio_output}.monitor" remix=true) - input_loopback_id=$(pactl load-module module-loopback sink="${mux_sink}" source="${audio_input}" remix=true) + input_loopback_id=$(pactl load-module module-loopback sink="${mux_sink}" source="${audio_input}" channels=1 remix=true) } teardown_mux_sink() { pactl unload-module "${mux_sink_id}" @@ -52,6 +83,10 @@ if [ -z "${mux_sink}" ]; then echo "mux: ${mux_sink}" fi +if [ -n "${no_mux}" ]; then + mux_sink="${audio_output}.monitor" +fi + if [ -n "${showkeys}" ]; then echo "Starting wshowkeys on ${video_output}" echo "WARNING: currently the -o flag to force display to a specific output is not implemented" >&2 @@ -61,4 +96,4 @@ if [ -n "${showkeys}" ]; then fi set -x -wf-recorder -c h264_vaapi -d /dev/dri/renderD128 -o "${video_output}" -a "${mux_sink}.monitor" -f "${output_file}" +wf-recorder -c h264_vaapi -d /dev/dri/renderD128 -x nv12 -o "${video_output}" -a "${mux_sink}.monitor" -f "${output_file}" diff --git a/bin/xdg-exec b/bin/xdg-exec index 787c502..e8f3ccb 100755 --- a/bin/xdg-exec +++ b/bin/xdg-exec @@ -1,7 +1,24 @@ #!/bin/sh +# +# DESCRIPTION: +# parses a .desktop file, that matches in name to `$0` +# and executes the `Exec` value. +# +# INSTALL: +# ln -s <path/to/this/script> /usr/local/bin/app.desktop +# + +XDG_DESKTOP_ENTRY_DIR=$HOME/.local/share/applications set -ex basepath=$(dirname "$0" | sed 's#/bin#/share/applications#') basename=$(basename "$0" | sed -e 's/^_//' -e 's/.desktop$//') -desktop=${basepath}/${basename}.desktop -bin=$(awk '/TryExec=/{split($0,l,"="); if (not system("command -v l[2]")){exit 1}} /Exec=/{print substr($0, index($0,"=")+1)}' "$desktop" | tr -d '\n' | sed "s/%.$//") -exec $bin +if [ -e "${XDG_DESKTOP_ENTRY_DIR}/${basename}.desktop" ]; then + desktop=${XDG_DESKTOP_ENTRY_DIR}/${basename}.desktop +else + desktop=${basepath}/${basename}.desktop +fi +bin=$(awk ' +/^TryExec=/{split($0,l,"="); if(not system("command -v l[2]")){exit 1}} +/^Exec=/{printf gensub(/Exec=([^%]+).*$/, "\\1", "")} +' "$desktop" | sed 's/%.$//') +exec ${bin} $@ |