diff options
-rwxr-xr-x | bin/extra/asciiext | 34 | ||||
-rwxr-xr-x | bin/extra/gdbs | 14 | ||||
-rwxr-xr-x | bin/extra/gml | 73 | ||||
-rwxr-xr-x | bin/extra/myts | 65 | ||||
-rwxr-xr-x | bin/extra/usbtoggle | 6 | ||||
-rwxr-xr-x | bin/guiscripts/slmpd | 5 | ||||
-rwxr-xr-x | bin/menuscripts/mdbsrv | 17 | ||||
-rwxr-xr-x | bin/menuscripts/mgame | 20 | ||||
-rw-r--r-- | config/common/mpd/mpd.conf | 4 | ||||
-rw-r--r-- | config/common/mpv/input.conf | 2 | ||||
-rw-r--r-- | config/essentials/shell/functions.sh | 4 | ||||
-rwxr-xr-x | config/essentials/zsh/.zprofile | 3 | ||||
-rw-r--r-- | config/essentials/zsh/comp.zsh | 212 | ||||
-rwxr-xr-x | config/home/.xprofile | 2 |
14 files changed, 377 insertions, 84 deletions
diff --git a/bin/extra/asciiext b/bin/extra/asciiext new file mode 100755 index 0000000..00e3408 --- /dev/null +++ b/bin/extra/asciiext @@ -0,0 +1,34 @@ +#!/bin/bash + +# heading index with div line +printf "\n "; # indent + +for x in {0..15}; do printf "%-3x" $x; done; +printf "\n%46s\n" | sed 's/ /-/g;s/^/ /'; + +# two lines with dots to represent control chars +c=$(echo "fa" | xxd -p -r | iconv -f 'CP437//' -t 'UTF-8') +printf "%32s" | sed 's/../'"$c"' /g;s/^/ 0 /;s/$/\n\n/' +printf "%32s" | sed 's/../'"$c"' /g;s/^/ 1 /' + +# convert dec to codepage 437 in a table +for x in {32..255}; +do + + # newline every 16 translated code values + (( x % 16 == 0 )) && printf "\n\n" + + # left index numbers + let "n = x % 15" + (( (x % 16) == 0 )) && printf "%-4x" $n | sed 's/0/f/;s/^/ /' + + # conversion of x integer value to symbol + printf "%02x" $x | xxd -p -r | iconv -f 'CP437//' -t 'UTF-8' | sed 's/.*/& /' + + # div line + (( x == 127 )) && printf "%46s" | sed 's/ /-/g;s/^/ /;i\ ' + +done +printf "%46s" | sed 's/ /-/g;s/^/\n /;s/$/\n /'; # div line +for x in {0..15}; do printf "%-3x" $x; done; +echo diff --git a/bin/extra/gdbs b/bin/extra/gdbs new file mode 100755 index 0000000..e0fa371 --- /dev/null +++ b/bin/extra/gdbs @@ -0,0 +1,14 @@ +#!/bin/sh + +gdbs="$HOME/.cache/gdbs" + +command="$@" +if [ -z "$command" ]; then + [ -f ] && command="$(cat "$gdbs" 2>/dev/null)" + [ "$command" ] || exit 1 +fi + +gdbserver :4200 $command + +echo "$command" > "$gdbs" + diff --git a/bin/extra/gml b/bin/extra/gml deleted file mode 100755 index f8d6b7e..0000000 --- a/bin/extra/gml +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/sh - -minecraft() -{ - instance="$( - ( - printf "default\n" - find ~/.local/share/multimc/instances \ - -maxdepth 1 -mindepth 1 \ - -type d \ - -printf "%f\n" | - grep -v '_LAUNCHER_TEMP' - ) | - commander -d -c -x)" - - [ "$instance" ] || exit 1 - [ "$instance" = "default" ] && instance="1.20.1" - - ips="none 192.168.178.79 192.168.178.52 10.7.0.1 mc.hypixel.net" - ip="$(for ip in $ips - do printf "%s\n" "$ip" - done | commander -d -c)" - - if [ "$ip" != 'none' ] - then setsid multimc -l "$instance" -s "$ip" > /dev/null 2>&1 - else - - world="$( - ( - printf "none\n" - find "$HOME"/.local/share/multimc/instances/"$instance"/.minecraft/saves/ \ - -mindepth 1 -maxdepth 1 \ - -type d \ - -printf "%f\n" - ) | commander -d -c -s)" - - [ -z "$world" ] && exit 1 - - if [ "$world" = 'none' ] - then setsid multimc -l "$instance" > /dev/null 2>&1 - else setsid multimc -l "$instance" -w "$world" > /dev/null 2>&1 - fi - - fi -} - -steam() -{ - choice="$( - cat <<-EOF | - 274190 broforce - 291550 brawlhalla - 1712840 tiny tina - 105600 terraria - kill - EOF - column -t -l 2 | commander -d -x -c | awk '{printf $1}')" - - case "$choice" in - kill) pkill steam ;; - "") ;; - *) setsid steam steam://rungameid/"$choice" ;; - esac - exit -} - -eval "$( - cat <<-EOF | commander -c -w 9 -y 3 - minecraft - steam - lutris - EOF -)" diff --git a/bin/extra/myts b/bin/extra/myts new file mode 100755 index 0000000..aea4842 --- /dev/null +++ b/bin/extra/myts @@ -0,0 +1,65 @@ +#!/bin/sh + +# Play a youtube song via yt-dlp, jq, fzf and play it with mpv or mpd. + +tsv="/tmp/ytsearch.tsv" +json="/tmp/ytsearch.json" + +# This is the preview code for fzf +if [ "$1" = "-p" ]; then + grep "^$2\s" "$tsv" | + cut -f 4,5,6 | tr '\t' '\n' | + while read -r channel; do + read -r timestamp + read -r views + printf '\033[2m%s\033[0m\n' "$channel" + printf '%s views\n' "$(numfmt --to=iec "$views")" + printf '\033[3m%s\033[0m\n' "$(date -d @"$timestamp" +'released on %d/%m/%y at %T')" + done + exit +fi + +# Whether to pass th --no-video flag to mpv +if [ "$1" = "-n" ]; then + noVideoFlag=1 + shift +fi + +# Whether to add the url to mpd +if [ "$1" = "-m" ]; then + toMPDFlag=1 + shift +fi + +q="$@" +if [ -z "$q" ]; then + >&2 printf 'Usage: %s query\n' "$0" + exit 1 +fi + +>&2 printf 'Searching..\n' +yt-dlp -j "ytsearch5:$q" | jq > "$json" + +jq -r '[.id,.title,.original_url,.channel,.timestamp,.view_count] | @tsv' "$json" > "$tsv" + +choice="$(cut -f 1,2,6 "$tsv" | + sort -t ' ' -k 3 | + cut -f 1,2 | + column -t -s ' ' | + fzf --with-nth "2.." --preview "$0"' -p {1}')" +[ "$choice" ] || exit 1 +choice="${choice%% *}" +url="$(grep "^$choice " "$tsv" | cut -f 3)" +[ "$url" ] || exit 2 + +rm -f "$tsv" "$json" + +if [ "$toMPDFlag" ]; then + >&2 printf 'Adding to mpd..\n' + mpc add "$(yt-dlp --prefer-insecure -g -f140 "$url")" +elif [ "$noVideoFlag" ]; then + mpv --no-video "$url" +else + mpv "$url" +fi +>&2 printf 'Done.\n' diff --git a/bin/extra/usbtoggle b/bin/extra/usbtoggle index 7adb2a2..d459ffd 100755 --- a/bin/extra/usbtoggle +++ b/bin/extra/usbtoggle @@ -4,7 +4,7 @@ # dependencies # - lsusb (to list usb devices) -# - commander (menu command) +# - fzf (menu command) # - doas (to run as root) device="$(lsusb | fzf)" @@ -21,5 +21,5 @@ file="$(grep -l "$p" $(grep -l "$v" /sys/bus/usb/devices/*/idVendor | sed 's/idVendor/idProduct/') | sed 's/idProduct$/authorized/')" -echo 0 | doas tee "$file" -echo 1 | doas tee "$file" +printf '%s\n' 0 | doas tee "$file" +printf '%s\n' 1 | doas tee "$file" diff --git a/bin/guiscripts/slmpd b/bin/guiscripts/slmpd index 96d9cd1..a102ba0 100755 --- a/bin/guiscripts/slmpd +++ b/bin/guiscripts/slmpd @@ -1,6 +1,7 @@ #!/bin/sh if mpc > /dev/null 2>&1 then - test "`mpc status %totaltime%`" = "0:00" || - echo -n " $(mpc status "%currenttime%/%totaltime%") $(mpc -f "[[%title%]|%file%]" | head -n -2) " + if [ "$(mpc status "%totaltime%")" != "0:00" ]; then + printf '%s %s' "$(mpc status "%currenttime%/%totaltime%")" "$(mpc -f "[[%title%]|%file%]" | head -n -2)" + fi fi diff --git a/bin/menuscripts/mdbsrv b/bin/menuscripts/mdbsrv new file mode 100755 index 0000000..81b5109 --- /dev/null +++ b/bin/menuscripts/mdbsrv @@ -0,0 +1,17 @@ +#!/bin/sh + +services() { + cat <<-EOF + 5030 slsksd + 9091 transmission + 8096 jellyfin + 80 ntfy + 24961 miniflux + 24880 pihole + 8384 syncthing +EOF +} + +service="$(services | column -t -l 2 | dmenu -c -x)" +[ "$service" ] || exit 1 +$BROWSER "http://192.168.178.79:${service%% *}" diff --git a/bin/menuscripts/mgame b/bin/menuscripts/mgame new file mode 100755 index 0000000..7c90a2b --- /dev/null +++ b/bin/menuscripts/mgame @@ -0,0 +1,20 @@ +#!/bin/sh + +steam_games() +{ + # List every manifest file and get the id of the games from the file names and the name of the + # game from the file. + find $HOME/.local/share/Steam/steamapps \ + -maxdepth 1 -type f -iname 'appmanifest_*.acf' | + while read -r File; do + Name="$(grep '"name"' "$File" | cut -f 4 -d '"')" + FileBaseName="${File%.acf}" + SteamID="${FileBaseName##*appmanifest_}" + printf '%s %s\n' "$SteamID" "$Name" + done +} + +Choice="$(steam_games | cut -f 2- -d' ' | dmenu -c -i -x)" +ID="$(steam_games | grep "[0-9]\+ $Choice" | cut -f 1 -d ' ')" + +setsid steam steam://rungameid/"$ID" diff --git a/config/common/mpd/mpd.conf b/config/common/mpd/mpd.conf index 095b345..f9e7f9e 100644 --- a/config/common/mpd/mpd.conf +++ b/config/common/mpd/mpd.conf @@ -5,8 +5,8 @@ pid_file "~/.config/mpd/pid" state_file "~/.local/state/mpd/state" auto_update "yes" restore_paused "yes" -bind_to_address "127.0.0.1" -port "6600" +# bind_to_address "/run/user/1000/mpd/socket" +# port "6600" audio_output { type "pulse" name "pulse audio" diff --git a/config/common/mpv/input.conf b/config/common/mpv/input.conf index b7932fa..5615d5f 100644 --- a/config/common/mpv/input.conf +++ b/config/common/mpv/input.conf @@ -193,7 +193,7 @@ LEFT seek -2 exact UP seek 2 keyframes DOWN seek -2 keyframes -ctrl-l cycle-values loop-file "inf" "no" # toggle infinite looping +ctrl+l cycle-values loop-file "inf" "no" # toggle infinite looping # Speed ] add speed 0.5 diff --git a/config/essentials/shell/functions.sh b/config/essentials/shell/functions.sh index 1aecccc..ab257fd 100644 --- a/config/essentials/shell/functions.sh +++ b/config/essentials/shell/functions.sh @@ -374,8 +374,8 @@ ssh() { for arg in $@; do if grep "Host $arg\s*\$" ~/.ssh/config > /dev/null 2>&1 ; then - # Disable notification by unsetting the DISPLAY varibles - DISPLAY= keyadd "$arg" 2> /dev/null + # Disable notification by unsetting the DISPLAY varibles + keyadd "$arg" 2> /dev/null break fi done diff --git a/config/essentials/zsh/.zprofile b/config/essentials/zsh/.zprofile index f67e3f7..2e40c32 100755 --- a/config/essentials/zsh/.zprofile +++ b/config/essentials/zsh/.zprofile @@ -1,6 +1,7 @@ #!/bin/sh -if [ "$TTY" = "/dev/tty1" ] && [ "$(id -u)" -ne 0 ]; then +if { [ "$TTY" = "/dev/tty1" ] || [ "$TTY" = "/dev/tty8" ]; } && + [ "$(id -u)" -ne 0 ]; then exec startx > /dev/null 2>&1 exit fi diff --git a/config/essentials/zsh/comp.zsh b/config/essentials/zsh/comp.zsh index 7a53337..7cded53 100644 --- a/config/essentials/zsh/comp.zsh +++ b/config/essentials/zsh/comp.zsh @@ -89,3 +89,215 @@ compdef _go_flag_complete wbr compdef esc="which" compdef gdbcore="which" compdef pkgfile="which" +#compdef ytui +compdef _ytui ytui + +# zsh completion for ytui -*- shell-script -*- + +__ytui_debug() +{ + local file="$BASH_COMP_DEBUG_FILE" + if [[ -n ${file} ]]; then + echo "$*" >> "${file}" + fi +} + +_ytui() +{ + local shellCompDirectiveError=1 + local shellCompDirectiveNoSpace=2 + local shellCompDirectiveNoFileComp=4 + local shellCompDirectiveFilterFileExt=8 + local shellCompDirectiveFilterDirs=16 + local shellCompDirectiveKeepOrder=32 + + local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder + local -a completions + + __ytui_debug "\n========= starting completion logic ==========" + __ytui_debug "CURRENT: ${CURRENT}, words[*]: ${words[*]}" + + # The user could have moved the cursor backwards on the command-line. + # We need to trigger completion from the $CURRENT location, so we need + # to truncate the command-line ($words) up to the $CURRENT location. + # (We cannot use $CURSOR as its value does not work when a command is an alias.) + words=("${=words[1,CURRENT]}") + __ytui_debug "Truncated words[*]: ${words[*]}," + + lastParam=${words[-1]} + lastChar=${lastParam[-1]} + __ytui_debug "lastParam: ${lastParam}, lastChar: ${lastChar}" + + # For zsh, when completing a flag with an = (e.g., ytui -n=<TAB>) + # completions must be prefixed with the flag + setopt local_options BASH_REMATCH + if [[ "${lastParam}" =~ '-.*=' ]]; then + # We are dealing with a flag with an = + flagPrefix="-P ${BASH_REMATCH}" + fi + + # Prepare the command to obtain completions + requestComp="${words[1]} __complete ${words[2,-1]}" + if [ "${lastChar}" = "" ]; then + # If the last parameter is complete (there is a space following it) + # We add an extra empty parameter so we can indicate this to the go completion code. + __ytui_debug "Adding extra empty parameter" + requestComp="${requestComp} \"\"" + fi + + __ytui_debug "About to call: eval ${requestComp}" + + # Use eval to handle any environment variables and such + out=$(eval ${requestComp} 2>/dev/null) + __ytui_debug "completion output: ${out}" + + # Extract the directive integer following a : from the last line + local lastLine + while IFS='\n' read -r line; do + lastLine=${line} + done < <(printf "%s\n" "${out[@]}") + __ytui_debug "last line: ${lastLine}" + + if [ "${lastLine[1]}" = : ]; then + directive=${lastLine[2,-1]} + # Remove the directive including the : and the newline + local suffix + (( suffix=${#lastLine}+2)) + out=${out[1,-$suffix]} + else + # There is no directive specified. Leave $out as is. + __ytui_debug "No directive found. Setting do default" + directive=0 + fi + + __ytui_debug "directive: ${directive}" + __ytui_debug "completions: ${out}" + __ytui_debug "flagPrefix: ${flagPrefix}" + + if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then + __ytui_debug "Completion received error. Ignoring completions." + return + fi + + local activeHelpMarker="_activeHelp_ " + local endIndex=${#activeHelpMarker} + local startIndex=$((${#activeHelpMarker}+1)) + local hasActiveHelp=0 + while IFS='\n' read -r comp; do + # Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker) + if [ "${comp[1,$endIndex]}" = "$activeHelpMarker" ];then + __ytui_debug "ActiveHelp found: $comp" + comp="${comp[$startIndex,-1]}" + if [ -n "$comp" ]; then + compadd -x "${comp}" + __ytui_debug "ActiveHelp will need delimiter" + hasActiveHelp=1 + fi + + continue + fi + + if [ -n "$comp" ]; then + # If requested, completions are returned with a description. + # The description is preceded by a TAB character. + # For zsh's _describe, we need to use a : instead of a TAB. + # We first need to escape any : as part of the completion itself. + comp=${comp//:/\\:} + + local tab="$(printf '\t')" + comp=${comp//$tab/:} + + __ytui_debug "Adding completion: ${comp}" + completions+=${comp} + lastComp=$comp + fi + done < <(printf "%s\n" "${out[@]}") + + # Add a delimiter after the activeHelp statements, but only if: + # - there are completions following the activeHelp statements, or + # - file completion will be performed (so there will be choices after the activeHelp) + if [ $hasActiveHelp -eq 1 ]; then + if [ ${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then + __ytui_debug "Adding activeHelp delimiter" + compadd -x "--" + hasActiveHelp=0 + fi + fi + + if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then + __ytui_debug "Activating nospace." + noSpace="-S ''" + fi + + if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then + __ytui_debug "Activating keep order." + keepOrder="-V" + fi + + if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then + # File extension filtering + local filteringCmd + filteringCmd='_files' + for filter in ${completions[@]}; do + if [ ${filter[1]} != '*' ]; then + # zsh requires a glob pattern to do file filtering + filter="\*.$filter" + fi + filteringCmd+=" -g $filter" + done + filteringCmd+=" ${flagPrefix}" + + __ytui_debug "File filtering command: $filteringCmd" + _arguments '*:filename:'"$filteringCmd" + elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then + # File completion for directories only + local subdir + subdir="${completions[1]}" + if [ -n "$subdir" ]; then + __ytui_debug "Listing directories in $subdir" + pushd "${subdir}" >/dev/null 2>&1 + else + __ytui_debug "Listing directories in ." + fi + + local result + _arguments '*:dirname:_files -/'" ${flagPrefix}" + result=$? + if [ -n "$subdir" ]; then + popd >/dev/null 2>&1 + fi + return $result + else + __ytui_debug "Calling _describe" + if eval _describe $keepOrder "completions" completions $flagPrefix $noSpace; then + __ytui_debug "_describe found some completions" + + # Return the success of having called _describe + return 0 + else + __ytui_debug "_describe did not find completions." + __ytui_debug "Checking if we should do file completion." + if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then + __ytui_debug "deactivating file completion" + + # We must return an error code here to let zsh know that there were no + # completions found by _describe; this is what will trigger other + # matching algorithms to attempt to find completions. + # For example zsh can match letters in the middle of words. + return 1 + else + # Perform file completion + __ytui_debug "Activating file completion" + + # We must return the result of this command, so it must be the + # last command, or else we must store its result to return it. + _arguments '*:filename:_files'" ${flagPrefix}" + fi + fi + fi +} + +# don't run the completion function when being source-ed or eval-ed +if [ "$funcstack[1]" = "_ytui" ]; then + _ytui +fi diff --git a/config/home/.xprofile b/config/home/.xprofile index 884b829..a4de557 100755 --- a/config/home/.xprofile +++ b/config/home/.xprofile @@ -23,3 +23,5 @@ unclutter --timeout 3 --jitter 50 -b & # signal-desktop & # discord & st -e "sh" "-c" "pgrep tmux && tmux a || tmux" & + +printf '%s\t%s' "$(date +%y_%m_%d-%T )" "$DISPLAY" >> ~/.x_displays.log & |