justfiles for automating various tasks on my workstation
1set unstable := true 2set script-interpreter := ["uv", "run", "--script"] 3 4# List systemd services 5[group('utilities')] 6lssvc: 7 sudo systemctl list-units --type=service 8 9# Copy public IPv4 address 10[group('utilities')] 11pubip: 12 curl -s -m 5 ipv4.icanhazip.com | xclip -selection clipboard 13 14# Copy SSH public key 15[group('utilities')] 16pubkey: 17 #!/usr/bin/env zsh 18 cat "${HOME}/.ssh/id_ed25519.pub" | tr -d '\n' | xclip -selection clipboard 19 echo "--> SSH public key copied to clipboard" 20 21# Generate a pseudo-random 16-character string 22[group('utilities')] 23genrand: 24 openssl rand -base64 16 25 26# Remove all .jpeg, .jpg, .png, .svg, .webp files from downloads 27[group('utilities')] 28rmimages: 29 #!/usr/bin/env bash 30 find "${HOME}/downloads" \ 31 -maxdepth 1 \ 32 -type f \ 33 \( -name "*.jpg" -o -name "*.jpg_original" -o -name "*.jpeg" -o -name "*.svg" -o -name "*.png" -o -name "*.webp" \) \ 34 -delete 35 36# Remove ISOs and disk images from downloads 37[group('utilities')] 38rmdimages: 39 #!/usr/bin/env bash 40 find "${HOME}/downloads" \ 41 -maxdepth 1 \ 42 -type f \ 43 \( -name "*.iso" -o -name "*.img" \) \ 44 -delete 45 46# Clear downloads folder 47[group('utilities')] 48cldl: 49 #!/usr/bin/env bash 50 rm -rf "${HOME}/downloads/"* 51 52# List zshrc aliases 53[group('utilities')] 54lsali: 55 #!/usr/bin/env zsh 56 _begin_line=$(grep -n "### ALIASES" ~/.zshrc | awk -F: '{print $1}') 57 _end_line=$(grep -n "### BINDINGS" ~/.zshrc | awk -F: '{print $1}') 58 _end_line=$(( $_end_line - 2 )) 59 _quit_line=$(( $_end_line + 1 )) 60 sed -n "${_begin_line},${_end_line}p;${_quit_line}q" ~/.zshrc | bat -l zsh 61 62# List zshrc functions 63[group('utilities')] 64lsfun: 65 #!/usr/bin/env zsh 66 _begin_line=$(grep -n "### FUNCTIONS" ~/.zshrc | awk -F: '{print $1}') 67 _end_line=$(grep -n "### FZF" ~/.zshrc | awk -F: '{print $1}') 68 _end_line=$(( $_end_line - 2 )) 69 _quit_line=$(( $_end_line + 1 )) 70 sed -n "${_begin_line},${_end_line}p;${_quit_line}q" ~/.zshrc | bat -l zsh 71 72# Quickly copy the Tailscale install command 73[group('utilities')] 74copy-ts-cmd: 75 echo "curl -fsSL https://tailscale.com/install.sh | sh" | xclip -selection clipboard 76 77# Copy GAME screenshots 78[group('utilities')] 79copy-screenshots: 80 #!/usr/bin/env bash 81 GAME=$(ugum choose eso starfield bg3) 82 case "$GAME" in 83 "eso") 84 find "${HOME}/.steam/steam/steamapps/compatdata/306130/pfx/drive_c/users/steamuser/Documents/Elder Scrolls Online/live/Screenshots" \ 85 -maxdepth 1 \ 86 -mindepth 1 \ 87 -exec cp -fv {} "${HOME}/nextcloud/pictures/eso_screenshots" \; 88 ;; 89 "starfield") 90 find "${HOME}/.steam/steam/steamapps/compatdata/1716740/pfx/drive_c/users/steamuser/My Documents/My Games/Starfield/Data/Textures/Photos" \ 91 -maxdepth 1 \ 92 -mindepth 1 \ 93 -not -name "*-thumbnail.png" \ 94 -exec cp -fv {} "${HOME}/nextcloud/pictures/starfield_screenshots" \; 95 ;; 96 "bg3") 97 find "${HOME}/games/gog/baldurs-gate-3/drive_c/users/steamuser/My Documents/Larian Studios/Baldur's Gate 3/Screenshots" \ 98 -maxdepth 1 \ 99 -mindepth 1 \ 100 -exec cp -fv {} "${HOME}/nextcloud/pictures/bg3_screenshots" \; 101 ;; 102 *) 103 echo "Unknown game" 104 ;; 105 esac 106 107# Create a .tar.gz archive from {{dir}} 108[group('utilities')] 109create-archive dir: 110 #!/usr/bin/env bash 111 set -eu 112 DIR_NAME={{ dir }} 113 archive_name="${DIR_NAME}-$(date '+%Y%m%d').tar.gz" 114 tar cvfz "$archive_name" "$DIR_NAME" 115 echo "Created archive $archive_name" 116 117# Get the day of the week a given date falls on 118[group('utilities')] 119dayofweek year month day: 120 #!/usr/bin/python3 121 import sys 122 from datetime import datetime 123 124 if __name__ == "__main__": 125 if len(sys.argv) != 4: 126 print("Usage: dayofweek <year> <month> <day>") 127 exit(1) 128 else: 129 print(datetime(int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])).strftime("%A")) 130 131# Download an open source license 132[group('utilities')] 133get-license: 134 #!/usr/bin/env bash 135 set -euo pipefail 136 base_url="https://api.github.com/licenses" 137 headers="Accept: application/vnd.github.drax-preview+json" 138 res=$(curl --silent --header $headers $base_url) 139 selection=$(echo "$res" | jq ".[].key" | tr -d '"' | gum choose --limit=1) 140 res=$(curl --silent --header $headers $base_url/$selection | jq ."body") 141 echo -e "$res" | tr -d '"' 142 143# Fetch and display public IP info 144[group('utilities')] 145[script] 146myip: 147 # /// script 148 # dependencies = [ 149 # "requests", 150 # ] 151 # /// 152 153 """ 154 myip - Fetch and display public IP information from ipinfo.io 155 """ 156 157 import json 158 import requests 159 160 if __name__ == "__main__": 161 KEY_COLOR = "\033[92m" 162 END_COLOR = "\033[0m" 163 164 response = requests.get("https://ipinfo.io", timeout=60) 165 json_data = json.loads(response.text) 166 167 print() 168 for item in json_data: 169 print(f"- {KEY_COLOR}{item.title():<16}{END_COLOR} {json_data[item]}") 170 171# vim: ts=4 sts=4 sw=4 et ft=just