diff options
Diffstat (limited to '.local/bin')
l--------- | .local/bin/awesome | 1 | ||||
-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/downloadgemist | 42 | ||||
-rwxr-xr-x | .local/bin/get-focussed-monitor | 43 | ||||
l--------- | .local/bin/herbstluftwm | 1 | ||||
-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-hosts | 6 | ||||
-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/open | 1 | ||||
-rwxr-xr-x | .local/bin/pkgsrc | 221 | ||||
-rwxr-xr-x | .local/bin/updot | 63 | ||||
-rwxr-xr-x | .local/bin/vol | 2 | ||||
-rwxr-xr-x | .local/bin/x | 14 | ||||
l--------- | .local/bin/xdg-open | 1 |
22 files changed, 558 insertions, 330 deletions
diff --git a/.local/bin/awesome b/.local/bin/awesome new file mode 120000 index 0000000..3da827c --- /dev/null +++ b/.local/bin/awesome @@ -0,0 +1 @@ +../share/wrapper.sh
\ No newline at end of file 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/downloadgemist b/.local/bin/downloadgemist new file mode 100755 index 0000000..d690ba8 --- /dev/null +++ b/.local/bin/downloadgemist @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +import argparse +import requests +import sys + +# Handle arguments +argparser = argparse.ArgumentParser( + description = "Command line utility to interact with downloadgemist.nl", +) +argparser.add_argument("url") + +args = argparser.parse_args() + +# Make the actual HTTP request +form = requests.post( + "https://www.downloadgemist.nl/core/hyperbridge.php", + data={ + "mode": "initiate", + "link": args.url, + "options": '{"size":"large","download_tt888":true}', + }, +) + +# Make sure the response is json +if form.headers.get("Content-Type").lower() != "application/json": + print("oh no") + sys.exit(1) + +json = form.json() + +print(form.json()) + +# Handle any errors +if json["status"] == 1: + print(form.json()["error"]) + sys.exit(form.json()["status"]) + +# Write the downloaded file +video = requests.get(json["file"]) + +open(json["filename"], "wb").write(video.content) diff --git a/.local/bin/get-focussed-monitor b/.local/bin/get-focussed-monitor deleted file mode 100755 index 4d7bbd4..0000000 --- a/.local/bin/get-focussed-monitor +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env raku - -use v6.d; - -sub MAIN ( - #Bool:D :$shell = False, - Bool:D :$coords = False, -) { - my @xrandr = shell('xrandr | grep -w connected', :out).out.slurp.lines; - my %monitors; - - my $mouse = shell('xdotool getmouselocation', :out).out.slurp.trim ~~ m/ - 'x:' $<x> = [ \d+ ] - \s* - 'y:' $<y> = [ \d+ ] - /; - - for @xrandr -> $monitor { - my $match = $monitor ~~ m/ - $<width> = [ \d+ ] - 'x' - $<height> = [ \d+ ] - '+' - $<x> = [ \d+ ] - '+' - $<y> = [ \d+ ] - /; - - next unless $match<x> ≤ $mouse<x> ≤ ($match<x> + $match<width>); - next unless $match<y> ≤ $mouse<y> ≤ ($match<y> + $match<height>); - - say qq[MONITOR="{$monitor.words.first}"]; - - if ($coords) { - say qq[W="{$match<width>}"]; - say qq[H="{$match<height>}"]; - say qq[X="{$match<x>}"]; - say qq[Y="{$match<y>}"]; - } - - last; - } -} diff --git a/.local/bin/herbstluftwm b/.local/bin/herbstluftwm new file mode 120000 index 0000000..3da827c --- /dev/null +++ b/.local/bin/herbstluftwm @@ -0,0 +1 @@ +../share/wrapper.sh
\ No newline at end of file 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-hosts b/.local/bin/kubectl-hosts deleted file mode 100755 index c347256..0000000 --- a/.local/bin/kubectl-hosts +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -kubectl get ing -o custom-columns=:.spec.rules[].host \ - | grep . \ - | sort \ - | uniq 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/open b/.local/bin/open index 584c430..9877708 100755 --- a/.local/bin/open +++ b/.local/bin/open @@ -61,6 +61,7 @@ multi sub cmd (HttpUrl $t where { $_.hostname.ends-with('gitlab.com') && $_.path multi sub cmd (HttpUrl $t where { $_.hostname.ends-with('gitlab.com') && $_.path[0].?fc eq 'xxllnc' }) { "chromium '$t'" } multi sub cmd (HttpUrl $t where *.hostname.ends-with('atlassian.net')) { "chromium '$t'" } multi sub cmd (HttpUrl $t where *.hostname.ends-with('aws.amazon.com')) { "chromium '$t'" } +multi sub cmd (HttpUrl $t where *.hostname.ends-with('awsapps.com')) { "chromium '$t'" } multi sub cmd (HttpUrl $t where *.hostname.ends-with('google.com')) { "chromium '$t'" } multi sub cmd (HttpUrl $t where *.hostname.ends-with('slack.com')) { "chromium '$t'" } multi sub cmd (HttpUrl $t where *.hostname.ends-with('zaaksysteem.net')) { "chromium '$t'" } diff --git a/.local/bin/pkgsrc b/.local/bin/pkgsrc deleted file mode 100755 index e6b1a7e..0000000 --- a/.local/bin/pkgsrc +++ /dev/null @@ -1,221 +0,0 @@ -#!/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. - -readonly PKGSRC_ROOT="$HOME/.local/src/pkgsrc" # TODO: Make configurable -readonly PKGSRC_DURATIONS="$XDG_DATA_HOME/pkgsrc/durations" - -main() -{ - PKGSRC_INIT="$(time_unix)" - - # Handle opts - while getopts ":h" opt - do - case "$opt" in - h) usage && exit 0 ;; - *) - printf "Invalid option passed: %s\n" "$OPTARG" >&2 - ;; - esac - done - - shift $(( OPTIND - 1 )) - - if [ $# -lt 1 ] - then - usage - exit 1 - fi - - PKGSRC_ACTION="action_$1" ; shift - - if ! command -V "$PKGSRC_ACTION" 2>/dev/null | grep -qwi function - then - usage - exit 1 - fi - - $PKGSRC_ACTION "$@" -} - -action_add() -{ - mkdir -p -- "$PKGSRC_DURATIONS" - - for package in "$@" - do - cd -- "$PKGSRC_ROOT" - - # cd wont fail here if pkg_resolve had no output - if ! cd -- "$(pkg_resolve "$package")" - then - printf "No package found for %s\n" "$package" - continue - fi - - bmake install \ - && bmake clean-depends \ - && bmake clean \ - || continue - - printf "%d\n" "$(( $(time_unix) - PKGSRC_INIT ))" \ - >> "$PKGSRC_DURATIONS/$package" - done - - printf "Installation took %s\n" "$(time_duration "$PKGSRC_INIT" "$(time_unix)")" -} - -action_del() -{ - for package in "$@" - do - cd -- "$PKGSRC_ROOT" - - if ! cd -- "$(pkg_resolve "$package")" - then - printf "No package found for %s\n" "$package" - continue - fi - - bmake deinstall - done -} - -action_grep() -{ - cd -- "$PKGSRC_ROOT" - - find . -maxdepth 2 -type d \ - | cut -c 3- \ - | grep "$@" -} - -action_init() -{ - export CVS_RSH="ssh" - - if [ ! -d "$PKGSRC_ROOT" ] - then - mkdir -p -- "${PKGSRC_ROOT%/*}" - cd -- "${PKGSRC_ROOT%/*}" - cvs -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -P pkgsrc || die 1 - fi - - if [ -d "$HOME/.pkgsrc" ] - then - printf "pkgsrc seems to have been initialized already at $HOME/.pkgsrc\n" - exit 1 - fi - - cd -- "$PKGSRC_ROOT/bootstrap" - rm -fr -- work - ./bootstrap --unprivileged --prefix="$HOME/.pkgsrc" # TODO: Make configurable - - printf "Bootstrapped in %s\n" "$(time_duration "$PKGSRC_INIT" "$(time_unix)")" -} - -action_opts() -{ - cd -- "$(pkg_resolve "$1")" || die "No package found for $1" - - bmake show-options -} - -action_time() -{ - for package in "$@" - do - if [ ! -f "$PKGSRC_DURATIONS/$package" ] - then - printf "%s: No timings\n" "$package" - continue - fi - - package_min="$(sort "$PKGSRC_DURATIONS/$package" | head -n 1)" - package_max="$(sort "$PKGSRC_DURATIONS/$package" | tail -n 1)" - package_avg="$(awk '{ sum += $1 } END { printf("%.0f", (sum / NR)) }' "$PKGSRC_DURATIONS/$package")" - - printf "%s: %s / %s / %s \n" \ - "$package" \ - "$(time_duration "$package_min")" \ - "$(time_duration "$package_avg")" \ - "$(time_duration "$package_max")" - done -} - -action_update() -{ - cd -- "$PKGSRC_ROOT" - - cvs up - - printf "Updated in %s\n" "$(time_duration "$PKGSRC_INIT" "$(time_unix)")" -} - -usage() -{ - cat <<EOF -Usage: - ${0##*/} -h <action> [target] - -Interact with pkgsrc. - -Options: - -h Show this help text and exit. - -Actions: - add Install one or more TARGETs. - del Uninstall one or more TARGETs. - grep Search for TARGET. - init Initialize the pkgsrc repository, and run the bootstrap script. - opts Show the options of TARGET. - time Show min, avg, max installation times for TARGETs. - update Update the pkgsrc repository. -EOF -} - -# -# Helper utilities -# - -die() -{ - printf "%s\n" "$*" >&2 - exit 1 -} - -pkg_resolve() -{ - readlink -f "$PKGSRC_ROOT"/*/"$1" || readlink -f "$PKGSRC_ROOT/$1" # What if both fail? -} - -time_unix() -{ - awk 'BEGIN{srand();print srand()}' -} - -time_duration() -{ - if [ ! -z "$2" ] - then - elapsed="$(( $2 - $1 ))" - else - elapsed="$1" - fi - - printf "%dh %02dm %02ds" \ - "$(( elapsed / 60 / 60 ))" \ - "$(( elapsed / 60 % 60))" \ - "$(( elapsed % 60 ))" -} - -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 ed5e26f..a47b1bc 100755 --- a/.local/bin/x +++ b/.local/bin/x @@ -12,12 +12,10 @@ then exit 1 fi - # Remove the old config - rm -f -- "$HOME/.xinitrc" - - # Add the base configuration - cat -- "$HOME/.local/etc/x/xinitrc" "$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 @@ -28,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 |