diff options
Diffstat (limited to '.local/bin')
-rwxr-xr-x | .local/bin/bl | 28 | ||||
-rwxr-xr-x | .local/bin/count (renamed from .local/bin/notify-send) | 38 | ||||
-rwxr-xr-x | .local/bin/dmenu | 22 | ||||
-rwxr-xr-x | .local/bin/hyprland-switch-tag | 161 | ||||
-rwxr-xr-x | .local/bin/import-pape | 19 | ||||
-rwxr-xr-x | .local/bin/ipass | 48 | ||||
l--------- | .local/bin/irc | 1 | ||||
-rwxr-xr-x | .local/bin/krokify | 30 | ||||
-rwxr-xr-x | .local/bin/kubectl-rageclean-pod | 17 | ||||
-rwxr-xr-x | .local/bin/kubectl-secret | 76 | ||||
-rwxr-xr-x | .local/bin/media-import | 53 | ||||
-rwxr-xr-x | .local/bin/updot | 63 | ||||
-rwxr-xr-x | .local/bin/vol | 2 | ||||
-rwxr-xr-x | .local/bin/x | 9 | ||||
l--------- | .local/bin/xdg-open | 1 |
15 files changed, 513 insertions, 55 deletions
diff --git a/.local/bin/bl b/.local/bin/bl index da1980e..ee71504 100755 --- a/.local/bin/bl +++ b/.local/bin/bl @@ -29,13 +29,25 @@ main() case "$1" in inc) - xbacklight -inc ${2:-5} + brightnessctl set +${2:-5}% notify="Brightness increased to $(brightness_level)%" ;; dec) - xbacklight -dec ${2:-5} + if [ $(brightness_level) -lt $(( ${2:-5} + 1 )) ] + then + brightnessctl set 1 + else + brightnessctl set ${2:-5}%- + fi + notify="Brightness lowered to $(brightness_level)%" ;; + set) + [ -z "$2" ] && usage && exit 1 + + brightnessctl set $2% + notify="Brightness set to $(brightness_level)%" + ;; esac notify-send -n 57492 -s -t 2 -i "$(brightness_icon)" "Backlight" "$notify" @@ -43,7 +55,7 @@ main() brightness_level() { - xbacklight -get + awk "BEGIN { printf(\"%d\", ($(brightnessctl get) / $(brightnessctl max)) * 100) }" } brightness_icon() @@ -61,8 +73,16 @@ usage() cat <<EOF Usage: ${0##*/} -h + ${0##*/} inc [level] + ${0##*/} dec [level] + ${0##*/} set <level> + +Alter the backlight intensity. -Nondescript +Subcommands: + inc Increase the volume by level, defaults to 5. + dec Decrease the volume by level, defaults to 5. + set Set the volume to level. Options: -h Show this help text and exit. diff --git a/.local/bin/notify-send b/.local/bin/count index 8dc67a0..cc02a71 100755 --- a/.local/bin/notify-send +++ b/.local/bin/count @@ -13,15 +13,10 @@ main() { # Handle opts - while getopts ":a:hi:n:st:" opt + while getopts ":h" opt do case "$opt" in - a) app=$OPTARG ;; h) usage && exit 0 ;; - i) icon=$OPTARG ;; - n) id=$OPTARG ;; - s) silent=1 ;; - t) timeout=$OPTARG ;; *) printf "Invalid option passed: %s\n" "$OPTARG" >&2 ;; @@ -30,34 +25,7 @@ main() shift $(( OPTIND - 1 )) - [ $# -lt 1 ] && usage && exit 1 - - if [ -z "$id" ] - then - id=$(awk -v min=10 -v max=10000 'BEGIN { srand(); print int(min+rand() * (max-min+1)) }') - fi - - gdbus call \ - --session \ - --dest org.freedesktop.Notifications \ - --object-path /org/freedesktop/Notifications \ - --method org.freedesktop.Notifications.Notify \ - "$app" \ - "$id" \ - "$icon" \ - "$1" \ - "$2" \ - "[]" \ - "{}" \ - "$((${timeout:-10} * 1000))" \ - > /dev/null - - if [[ -z "$silent" ]] - then - printf "%d\n" "$id" - fi - - exit 0 + cat - | sort | uniq -c | sort -h } usage() @@ -66,7 +34,7 @@ usage() Usage: ${0##*/} -h -Nondescript +Count occurrences of unique lines. Options: -h Show this help text and exit. diff --git a/.local/bin/dmenu b/.local/bin/dmenu index 78cdf52..6c1494b 100755 --- a/.local/bin/dmenu +++ b/.local/bin/dmenu @@ -1,8 +1,20 @@ #!/usr/bin/env sh -if ! command -v rofi > /dev/null -then - exec /usr/bin/dmenu "$@" -fi +main() { + if [ -n "$WAYLAND_DISPLAY" ] + then + exec fuzzel --dmenu "$@" + fi -exec rofi -dmenu "$@" + if [ -n "$DISPLAY" ] + then + if command -v rofi > /dev/null + then + exec rofi -dmenu "$@" + fi + + exec /usr/bin/dmenu "$@" + fi +} + +main "$@" diff --git a/.local/bin/hyprland-switch-tag b/.local/bin/hyprland-switch-tag new file mode 100755 index 0000000..06840c9 --- /dev/null +++ b/.local/bin/hyprland-switch-tag @@ -0,0 +1,161 @@ +#!/usr/bin/env bash + +# Pascal Jaeger <pascal.jaeger@leimstift.de> + +# utils +green="\033[0;32m" +red="\033[0;31m" +blue="\033[0;34m" +nocolor="\033[0m" + +#util functions +check() { + command -v "$1" 1>/dev/null +} + +ok() { + echo -e "[$green $nocolor] $*" +} + +err() { + echo -e "[$red $nocolor] $*" +} +optional() { + echo -e "[$blue $nocolor] $*" +} + +notify() { + # shellcheck disable=SC2015 + check notify-send && { + notify-send "$@" + } || { + echo "$@" + } +} + +checkUtils() { + # shellcheck disable=SC2015 + check grep && ok "grep" || err "grep" + # shellcheck disable=SC2015 + check grep && ok "cut" || err "cut" + # shellcheck disable=SC2015 + check notify-send && ok "notify-send (Optional)" || optional "notify-send (Optional)" + exit +} + +basicChecks() { + check hyprctl || { + notify "Seriously mate!!" "Start Hyprland before this script" + exit 1 + } + pgrep -x Hyprland &>/dev/null || { + notify "Make Sure Hyprland Session is running." + exit 1 + } +} + +help() { + cat <<EOF + This is a bash script to move arbitrary workspace to arbritrary monitor and to swap workspaces between + monitors if the desired workspace is already active on a monitor for Hyprland using hyprctl. + + flags: + -h: Displays This help menu + -c: Checks for all dependencies + + Usage: try_swap_workspace [WORKSPACE] + bind = ALT,1,exec, /path/to/try_swap_workspace/binary 1 + (where the last 1 is the workspace that should be shown on the currently active monitor) + +EOF +} + +getArgs() { + while [ "$#" -gt 0 ]; do + case "$1" in + -h | --help) + help + exit 0 + ;; + -c) + checkUtils + ;; + (*[!0-9]*) + # contains non-numbers + help + echo "" + echo "Wrong argument given" + exit 1 + ;; + *) + # only nubers left, so good + switch_or_swap "$1" + ;; + esac + shift + done +} + + +#variables +mon_wrkspcs=() + +get_active_mon() { + echo $(($(hyprctl monitors | grep 'focused' | grep -n 'yes' | cut -c1)-1)) +} + +get_workspaces_array() { + local workspaces + workspaces=$(hyprctl monitors | grep 'active workspace' | cut -f3 -d' ') + SAVEIFS=$IFS + IFS=$'\n' + mon_wrkspcs=($workspaces) + IFS=$SAVEIFS +} + +# first argument: workspace to switch to +# second argument: monitor to switch workspace on +switch_workspace() { + local target_wrkspc=$1 + local target_mon=$2 + hyprctl dispatch moveworkspacetomonitor "$target_wrkspc" "$target_mon" + hyprctl dispatch workspace "$target_wrkspc" +} +# first argument: monitor the workspace should go to +# second argument: monitor the workspace is currently displayed on +swap_workspace() { + local target_mon=$1 + local source_mon=$2 + hyprctl dispatch swapactiveworkspaces "$target_mon" "$source_mon" +} + +# first argument: workspace to switch to active monitor +switch_or_swap() { + target_mon=$(get_active_mon) + target_wrkspc=$1 + get_workspaces_array + # check if the workspace is currently displayed on another monitor + local currently_active_on_mon=-1 + for (( i=0; i<${#mon_wrkspcs[@]}; i++ )) + do + if [[ "$target_wrkspc" == "${mon_wrkspcs[$i]}" ]]; then + currently_active_on_mon=$i + fi + done + if [[ $currently_active_on_mon -lt 0 ]]; then + # workspace is not active on any monitor, do a normal switch + ok "switching workspace $target_wrkspc to monitor $target_mon" + switch_workspace "$target_wrkspc" "$target_mon" + else + # workspace is already active on other monitor, swap workspaces between monitor + ok "swapping workspaces between $target_mon to monitor $currently_active_on_mon" + swap_workspace "$target_mon" "$currently_active_on_mon" + fi +} + +main() { + basicChecks + getArgs "$@" +} + +main "$@" diff --git a/.local/bin/import-pape b/.local/bin/import-pape new file mode 100755 index 0000000..b72c169 --- /dev/null +++ b/.local/bin/import-pape @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +readonly PAPEDIR="$HOME/pictures/wallpapers" + +main() { + for s in "$@" + do + local format="$(identify -format "%m" "$s" | awk '{ print(tolower($0)) }')" + local resolution="$(identify -format "%wx%h" "$s")" + local hash="$(sha1sum "$s" | awk '{ print $1 }')" + local destination="$PAPEDIR/$resolution/$hash.$format" + + mkdir -pv -- "$PAPEDIR/$resolution" + printf "Importing %s to %s\n" "$s" "$destination" + mv -- "$s" "$destination" + done +} + +main "$@" diff --git a/.local/bin/ipass b/.local/bin/ipass index b19137a..4f555e4 100755 --- a/.local/bin/ipass +++ b/.local/bin/ipass @@ -1,19 +1,51 @@ #! /usr/bin/env sh -main() -{ +main() { cd -- "$HOME/.password-store" || exit 1 - file="$(find ./* -type f | sed 's-^\./--' | sed 's-\.gpg$--' | dmenu)" - dmenu_exit=$? + if [ -n "$WAYLAND_DISPLAY" ] + then + file="$(pass_list | fuzzel -d)" + pass_get "$file" | wl-copy + + notify "Copied $file to clipboard!" + exit 0 + fi - if [ "$dmenu_exit" -ne 0 ] + if [ -n "$DISPLAY" ] then - exit 2 + file="$(pass_list | dmenu)" + pass_get "$file" | xdotool type --file - + dmenu_exit=$? + + if [ "$dmenu_exit" -ne 0 ] + then + notify "Error typing $file" + exit 2 + fi + + notify "Typing $file" + + exit 0 fi - pass show "$file" | head -n 1 | perl -pe 'chomp' | xdotool type --file - - notify-send -i "dialog-password" "ipass" "$file" + notify "No graphical environment detected" +} + +pass_list() { + find ./* -type f \ + | sed 's-^\./--' \ + | sed 's-\.gpg$--' +} + +pass_get() { + pass show "$1" \ + | head -n 1 \ + | perl -pe 'chomp' +} + +notify() { + notify-send -i "dialog-password" "ipass" "$*" } main "$@" diff --git a/.local/bin/irc b/.local/bin/irc new file mode 120000 index 0000000..3da827c --- /dev/null +++ b/.local/bin/irc @@ -0,0 +1 @@ +../share/wrapper.sh
\ No newline at end of file diff --git a/.local/bin/krokify b/.local/bin/krokify new file mode 100755 index 0000000..a01c1f6 --- /dev/null +++ b/.local/bin/krokify @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import argparse +import base64 +import sys +import zlib + +def main(): + arg_parser = argparse.ArgumentParser( + prog='krokify', + description='Turn a given file into a kroki link', + ) + arg_parser.add_argument("file", default="-", help="Path to the file to krokify, or - to read from stdin") + arg_parser.add_argument("-f", "--format", default="svg", help="Which output format to use") + arg_parser.add_argument("-s", "--service", required=True, help="Which back-end service to use") + arg_parser.add_argument("-u", "--base-url", default="https://kroki.tyil.nl", help="The base URL of the Kroki server") + + args = arg_parser.parse_args() + + if args.file == "-": + stream = sys.stdin + else: + stream = open(args.file, "r") + + url = base64.urlsafe_b64encode(zlib.compress(stream.read().encode('utf-8'), 9)).decode('ascii') + + print(f"{args.base_url}/{args.service}/{args.format}/{url}") + +if __name__ == "__main__": + main() diff --git a/.local/bin/kubectl-rageclean-pod b/.local/bin/kubectl-rageclean-pod new file mode 100755 index 0000000..bbd3ba7 --- /dev/null +++ b/.local/bin/kubectl-rageclean-pod @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. + +main() { + kubectl delete pod --force --grace-period=0 "$@" +} + +main "$@" diff --git a/.local/bin/kubectl-secret b/.local/bin/kubectl-secret new file mode 100755 index 0000000..ab2e924 --- /dev/null +++ b/.local/bin/kubectl-secret @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. + +import argparse +import base64 +import sys + +import ruamel.yaml +import ruamel.yaml.scalarstring + +def main(): + argparser = argparse.ArgumentParser(description="Encode or decode Kubernetes Secrets.") + argparser.add_argument("mode", help="Mode of operation, either encode or decode.", choices=["encode", "decode"]) + argparser.add_argument("path", help="Path to the file to operate on. If set to -, STDIN will be used instead.", default="-", nargs="?") + + args = argparser.parse_args() + yaml = ruamel.yaml.YAML() + + # Deduce whether to read from STDIN or open a file handle to a given path + if args.path == "-": + buffer = sys.stdin + else: + buffer = open(args.path) + + # Load the manifest + manifest = yaml.load(buffer.read()) + + # Handle any known potential issues + if not "kind" in manifest: + print("No kind in manifest", file=sys.stderr) + return 3 + + if manifest["kind"] != "Secret": + print("Not a secret", file=sys.stderr) + return 4 + + if not "data" in manifest: + manifest["data"] = {} + + # Call appropriate function with the manifest + manifest = globals()["secret_" + args.mode](manifest) + + # Write the processed manifest back as yaml + yaml.dump(manifest, sys.stdout) + + return 0 + +def secret_decode(manifest): + for key in manifest["data"].keys(): + # Decode the data + manifest["data"][key] = base64.b64decode(manifest["data"][key]).decode("utf-8") + + # Turn this element into a block quoted string if there are newlines + if "\n" in manifest["data"][key]: + manifest["data"][key] = ruamel.yaml.scalarstring.LiteralScalarString(manifest["data"][key]) + + return manifest + +def secret_encode(manifest): + for key in manifest["data"].keys(): + # Encode the data + manifest["data"][key] = base64.b64encode(str(manifest["data"][key]).encode("utf-8")).decode("utf-8") + + return manifest + +if __name__ == '__main__': + sys.exit(main()) diff --git a/.local/bin/media-import b/.local/bin/media-import new file mode 100755 index 0000000..a1a99b2 --- /dev/null +++ b/.local/bin/media-import @@ -0,0 +1,53 @@ +#!/bin/bash + +main() { + # Show help + if (( $# < 2 )) + then + echo "You need help" + return 2 + fi + + # Set the paths + local basedir="${MEDIA_BASEDIR:-/var/media}" + local mediadir="$basedir/$1" ; shift + + # Ask for confirmation through a keypress + printf "Going to import %d URIs to %s...\n" "$#" "$mediadir" + read -s -n1 + + # Loop over all given args + for uri in "$@" + do + case "$uri" in + http://*) import_http "$mediadir" "$uri" ;; + https://*) import_http "$mediadir" "$uri" ;; + *) import_local "$mediadir" "$uri" ;; + esac + done +} + +import_http() { + local dest="$1" ; shift + local uri="$1" ; shift + local temp="$(mktemp)" + + wget -c -O "$temp" "$uri" + + local output="$(import_local "$dest" "$temp" | awk '{ print $NF }')" + + printf "%s -> %s\n" "$uri" "$output" +} + +import_local() { + local dest="$1" ; shift + local uri="$1" ; shift + local hash="$(sha1sum "$uri" | awk '{ print $1 }')" + local ext="$(identify "$uri" | awk '{ print tolower($2) }')" + local out="$dest/$hash.$ext" + + mv -- "$uri" "$out" + printf "%s -> %s\n" "$uri" "$out" +} + +main "$@" diff --git a/.local/bin/updot b/.local/bin/updot new file mode 100755 index 0000000..f0179ad --- /dev/null +++ b/.local/bin/updot @@ -0,0 +1,63 @@ +#!/bin/sh + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. + +main() +{ + DOTFILES_REMOTE="origin" + DOTFILES_BRANCH="master" + + # Handle opts + while getopts ":h" opt + do + case "$opt" in + b) DOTFILES_BRANCH="$OPTARG" ;; + h) usage && exit 0 ;; + u) DOTFILES_REMOTE="$OPTARG" ;; + *) + printf "Invalid option passed: %s\n" "$OPTARG" >&2 + ;; + esac + done + + shift $(( OPTIND - 1 )) + + # Stash any pending changes + git -C "$HOME" stash + + # Update the main repository + git -C "$HOME" fetch "$DOTFILES_REMOTE" "$DOTFILES_BRANCH" + git -C "$HOME" reset --hard "$DOTFILES_REMOTE/$DOTFILES_BRANCH" + + # Pull updates for all submodules + git -C "$HOME" submodule update --init --recursive --remote + + # Apply the stash + git -C "$HOME" stash apply +} + +usage() +{ + cat <<EOF +Usage: + ${0##*/} -h + ${0##*/} [-b <branch>] [-u <remote>] + +Utility application for dotfile maintenance. + +Options: + -b The name of the branch to use, defaults to "master" + -h Show this help text and exit. + -u The name of the remote to use, defaults to "origin" +EOF +} + +main "$@" diff --git a/.local/bin/vol b/.local/bin/vol index 8993689..84c913e 100755 --- a/.local/bin/vol +++ b/.local/bin/vol @@ -40,6 +40,8 @@ main() notify="Decreased '$DEFAULT_SINK_NAME' ($DEFAULT_SINK_INDEX) to $(volume_level)%" ;; set) + [ -z "$2" ] && usage && exit 1 + pactl set-sink-volume @DEFAULT_SINK@ $2% > /dev/null notify="Set '$DEFAULT_SINK_NAME' ($DEFAULT_SINK_INDEX) to $(volume_level)%" ;; diff --git a/.local/bin/x b/.local/bin/x index d00fda0..a47b1bc 100755 --- a/.local/bin/x +++ b/.local/bin/x @@ -12,7 +12,10 @@ then exit 1 fi - cp -v -- "$HOME/.local/etc/x/xinit.d/$1.rc" "$HOME/.xinitrc" + cat \ + "$HOME/.local/etc/x/xinitrc" \ + "$HOME/.local/etc/x/xinit.d/$1.rc" \ + > "$HOME/.xinitrc" fi # Make sure the xinitrc exists, just in case @@ -23,4 +26,6 @@ then fi # start the X session -exec startx +startx +systemctl --user stop desktop-x11.target +systemctl --user stop desktop.target diff --git a/.local/bin/xdg-open b/.local/bin/xdg-open deleted file mode 120000 index ce4a72b..0000000 --- a/.local/bin/xdg-open +++ /dev/null @@ -1 +0,0 @@ -open
\ No newline at end of file |