diff options
Diffstat (limited to 'shenanigans.sh')
| -rwxr-xr-x | shenanigans.sh | 198 |
1 files changed, 0 insertions, 198 deletions
diff --git a/shenanigans.sh b/shenanigans.sh deleted file mode 100755 index 5af5fdf..0000000 --- a/shenanigans.sh +++ /dev/null | |||
| @@ -1,198 +0,0 @@ | |||
| 1 | # Magical environment variables. | ||
| 2 | NIX_SHELL_PRESERVE_PROMPT=1 | ||
| 3 | TERM=xterm-256color | ||
| 4 | VISUAL=vim | ||
| 5 | EDITOR=vim | ||
| 6 | |||
| 7 | parse_git_branch() { | ||
| 8 | git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | ||
| 9 | } | ||
| 10 | |||
| 11 | is_inside_nix_shell() { | ||
| 12 | nix_shell_name="$(basename "$IN_NIX_SHELL" 2>/dev/null)" | ||
| 13 | if [[ -n "$nix_shell_name" ]]; then | ||
| 14 | echo " \e[0;36m(nix-shell)\e[0m" | ||
| 15 | fi | ||
| 16 | } | ||
| 17 | |||
| 18 | # Better prompt. | ||
| 19 | export PS1="[\033[38;5;166m\]\u@\h\[$(tput sgr0)\]]$(is_inside_nix_shell)\[\033[33m\]\$(parse_git_branch)\[\033[00m\] \w\[$(tput sgr0)\] \n$ " | ||
| 20 | |||
| 21 | # General aliases. | ||
| 22 | alias ls='ls --color=none' | ||
| 23 | alias l='ls -lh --color=none' | ||
| 24 | alias ll='ls -lha --color=none' | ||
| 25 | alias t='tree -L 2' | ||
| 26 | alias ..='cd ..' | ||
| 27 | alias grep='grep --color=always' | ||
| 28 | alias less='less -R' | ||
| 29 | alias tmux='tmux -u' | ||
| 30 | alias vi='vim' | ||
| 31 | alias server='python3 -m http.server 6969' | ||
| 32 | |||
| 33 | # Custom folder jump commands. | ||
| 34 | alias p='cd ~/Vault/projects' | ||
| 35 | alias j='cd ~/Junk/current' | ||
| 36 | alias d='cd ~/Downloads' | ||
| 37 | |||
| 38 | # Additional path settings. | ||
| 39 | export PATH=$HOME/Applications:$PATH | ||
| 40 | export PATH=$HOME/go/bin:$PATH | ||
| 41 | export PATH=/usr/local/go/bin:$PATH | ||
| 42 | |||
| 43 | # History and search. Stolen from J. | ||
| 44 | HISTCONTROL=ignoreboth | ||
| 45 | shopt -s histappend | ||
| 46 | export HISTSIZE= | ||
| 47 | export HISTFILESIZE= | ||
| 48 | export HISTFILE=~/.bash_history_infinite | ||
| 49 | PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}" | ||
| 50 | bind '"\e[A": history-search-backward' | ||
| 51 | bind '"\e[B": history-search-forward' | ||
| 52 | export HSTR_CONFIG=hicolor | ||
| 53 | if [[ $- =~ .i. ]]; then bind '"\C-h": "\C-a hstr -- \C-j"'; fi | ||
| 54 | |||
| 55 | # Machine provision script for essential software. | ||
| 56 | # This is meant to be used on Debian 11+. | ||
| 57 | provision() { | ||
| 58 | doas apt install \ | ||
| 59 | build-essential git gcc make busybox cifs-utils tree hstr s3cmd \ | ||
| 60 | xmlstarlet htop nvtop tmux picom scrot xclip mc ripgrep jq \ | ||
| 61 | rsync doas newsboat entr clang clang-tidy clang-tools \ | ||
| 62 | libx11-dev libxinerama-dev libxft-dev x11-xserver-utils \ | ||
| 63 | podman podman-compose | ||
| 64 | } | ||
| 65 | |||
| 66 | # Backup to NAS function. Much wow! | ||
| 67 | backup() { | ||
| 68 | CWD=$(pwd) | ||
| 69 | VHOME=/home/$USER/Vault | ||
| 70 | ME=$(whoami)@$(hostname) | ||
| 71 | |||
| 72 | mkdir -p $VHOME/dotfiles | ||
| 73 | cd $VHOME/dotfiles | ||
| 74 | |||
| 75 | # Make a copy of certain files. | ||
| 76 | rsync -azhv /home/$USER/.bash_history_infinite bash_history_infinite | ||
| 77 | rsync -azhv /home/$USER/.ssh/ ssh | ||
| 78 | rsync -azhv /home/$USER/.aws/ aws | ||
| 79 | rsync -azhv /home/$USER/.gnupg/ gnupg/ | ||
| 80 | |||
| 81 | # Sync with NAS. | ||
| 82 | rsync -azhvpog \ | ||
| 83 | --exclude '.venv/' \ | ||
| 84 | --exclude '.git/' \ | ||
| 85 | --exclude '.import/' \ | ||
| 86 | --exclude '.godot/' \ | ||
| 87 | --exclude '.zig-cache/' \ | ||
| 88 | --exclude 'node_modules/' \ | ||
| 89 | --exclude 'digg-v5/' \ | ||
| 90 | --delete \ | ||
| 91 | $VHOME/ /media/Void/Backup/$ME/ | ||
| 92 | |||
| 93 | # Add to log file. | ||
| 94 | echo `date +"%D %T"` >> ~/.vault.log | ||
| 95 | notify-send "Backup finished successfully." | ||
| 96 | |||
| 97 | # Return back to original directory | ||
| 98 | cd $CWD | ||
| 99 | } | ||
| 100 | |||
| 101 | # Simple ticket system based on https://github.com/mitjafelicijan/ticket. | ||
| 102 | export TICKETS=~/Vault/tickets | ||
| 103 | tt() { | ||
| 104 | if [ "$(uname -s)" != "Linux" ]; then | ||
| 105 | printf "Currently only Linux is supported.\n" | ||
| 106 | return 1 | ||
| 107 | fi | ||
| 108 | |||
| 109 | if [ -z "$TICKETS" ]; then | ||
| 110 | TICKETS="$HOME/tickets" | ||
| 111 | fi | ||
| 112 | |||
| 113 | mkdir -p $TICKETS | ||
| 114 | |||
| 115 | # Display open tickets if no argument provided. | ||
| 116 | if [ -z "$1" ]; then | ||
| 117 | echo "`tt -o`" | ||
| 118 | return 0 | ||
| 119 | fi | ||
| 120 | |||
| 121 | case $1 in | ||
| 122 | -n|-new) | ||
| 123 | # ticket_id=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 10 | head -n 1) | ||
| 124 | ticket_id=$(echo -n "$(date)" | md5sum | cut -c 9-20) | ||
| 125 | ticket_file=$TICKETS/$ticket_id | ||
| 126 | printf "id: %s\n" $ticket_id > $ticket_file | ||
| 127 | printf "responsible: %s\n" `whoami`@`hostname` >> $ticket_file | ||
| 128 | printf "created: %s\n" "`date`" >> $ticket_file | ||
| 129 | printf "status: open\n" >> $ticket_file | ||
| 130 | printf "title: ?\n" >> $ticket_file | ||
| 131 | printf "====\n" >> $ticket_file | ||
| 132 | printf "Description...\n" >> $ticket_file | ||
| 133 | $EDITOR $ticket_file | ||
| 134 | ;; | ||
| 135 | -o|-open) | ||
| 136 | printf "%-14s %-21s %s\n" "Ticket ID" "Created at" "Title" | ||
| 137 | printf "%0.s-" {1..100} | ||
| 138 | printf "\n" | ||
| 139 | grep --color=never -l 'status: open' $TICKETS/* | while read file; do | ||
| 140 | id=$(head -n 1 "$file" | tail -n 1 | awk '{ print $2 }') | ||
| 141 | title=$(head -n 5 "$file" | tail -n 1 | awk '{$1=""; print $0}') | ||
| 142 | cdate=$(head -n 3 "$file" | tail -n 1 | awk '{$1=""; print $0}') | ||
| 143 | cdate_fmt=$(date -d "$cdate" "+%Y-%m-%d %H:%M:%S") | ||
| 144 | printf "%-14s %-20s %.66s\n" "$id" "$cdate_fmt" "$title" | ||
| 145 | done | ||
| 146 | ;; | ||
| 147 | -c|-closed) | ||
| 148 | printf "%-14s %-21s %s\n" "Ticket ID" "Created at" "Title" | ||
| 149 | printf "%0.s-" {1..100} | ||
| 150 | printf "\n" | ||
| 151 | grep --color=never -l 'status: closed' $TICKETS/* | while read file; do | ||
| 152 | id=$(head -n 1 "$file" | tail -n 1 | awk '{ print $2 }') | ||
| 153 | title=$(head -n 5 "$file" | tail -n 1 | awk '{$1=""; print $0}') | ||
| 154 | cdate=$(head -n 3 "$file" | tail -n 1 | awk '{$1=""; print $0}') | ||
| 155 | cdate_fmt=$(date -d "$cdate" "+%Y-%m-%d %H:%M:%S") | ||
| 156 | printf "%-14s %-20s %.66s\n" "$id" "$cdate_fmt" "$title" | ||
| 157 | done | ||
| 158 | ;; | ||
| 159 | -h|-help) | ||
| 160 | printf "Usage: ticket [option]\n" | ||
| 161 | printf " -n, -new creates a new ticket\n" | ||
| 162 | printf " -o, -open lists open tickets\n" | ||
| 163 | printf " -c, -closed lists closed tickets\n" | ||
| 164 | printf " -h, -help shows this help\n" | ||
| 165 | ;; | ||
| 166 | *) | ||
| 167 | if [ -e "$TICKETS/$1" ] && [ -f "$TICKETS/$1" ]; then | ||
| 168 | $EDITOR "$TICKETS/$1" | ||
| 169 | else | ||
| 170 | printf "Ticket not found: $TICKETS/$1\n" | ||
| 171 | fi | ||
| 172 | ;; | ||
| 173 | esac | ||
| 174 | } | ||
| 175 | |||
| 176 | # Toggles between pulseaudio sinks in round-robin. | ||
| 177 | togglesink() { | ||
| 178 | sinks=($(pactl list short sinks | awk '{print $2}')) | ||
| 179 | current_sink=$(pactl get-default-sink) | ||
| 180 | current_index=-1 | ||
| 181 | |||
| 182 | for i in "${!sinks[@]}"; do | ||
| 183 | if [[ "${sinks[$i]}" == "$current_sink" ]]; then | ||
| 184 | current_index=$i | ||
| 185 | break | ||
| 186 | fi | ||
| 187 | done | ||
| 188 | |||
| 189 | if [[ $current_index -eq -1 ]]; then | ||
| 190 | next_index=0 | ||
| 191 | else | ||
| 192 | next_index=$(( (current_index + 1) % ${#sinks[@]} )) | ||
| 193 | fi | ||
| 194 | |||
| 195 | pactl set-default-sink "${sinks[$next_index]}" | ||
| 196 | notify-send "Switched to sink: ${sinks[$next_index]}" | ||
| 197 | } | ||
| 198 | |||
