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=$(gum choose eso starfield bg3) 82 if [ "$GAME" = "bg3" ]; then 83 find "${HOME}/games/gog/baldurs-gate-3/drive_c/users/steamuser/My Documents/Larian Studios/Baldur's Gate 3/Screenshots" \ 84 -maxdepth 1 \ 85 -mindepth 1 \ 86 -exec cp -fv {} "${HOME}/nextcloud/pictures/bg3_screenshots" \; 87 fi 88 89 if [ "$GAME" = "eso" ]; then 90 find "${HOME}/.steam/steam/steamapps/compatdata/306130/pfx/drive_c/users/steamuser/Documents/Elder Scrolls Online/live/Screenshots" \ 91 -maxdepth 1 \ 92 -mindepth 1 \ 93 -exec cp -fv {} "${HOME}/nextcloud/pictures/eso_screenshots" \; 94 fi 95 96 if [ "$GAME" = "starfield" ]; then 97 find "${HOME}/.steam/steamapps/compatdata/1716740/pfx/drive_c/users/steamuser/My Documents/My Games/Starfield/Data/Textures/Photos" \ 98 -maxdepth 1 \ 99 -mindepth 1 \ 100 -not -name "*-thumbnail.png" \ 101 -exec cp -fv {} "${HOME}/nextcloud/pictures/starfield_screenshots" \; 102 fi 103 104# Create a .tar.gz archive from {{dir}} 105[group('utilities')] 106create-archive dir: 107 #!/usr/bin/env bash 108 set -eu 109 DIR_NAME={{ dir }} 110 archive_name="${DIR_NAME}-$(date '+%Y%m%d').tar.gz" 111 tar cvfz "$archive_name" "$DIR_NAME" 112 echo "Created archive $archive_name" 113 114# Get the day of the week a given date falls on 115[group('utilities')] 116dayofweek year month day: 117 #!/usr/bin/python3 118 import sys 119 from datetime import datetime 120 121 if __name__ == "__main__": 122 if len(sys.argv) != 4: 123 print("Usage: dayofweek <year> <month> <day>") 124 exit(1) 125 else: 126 print(datetime(int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])).strftime("%A")) 127 128# Download an open source license 129[group('utilities')] 130get-license: 131 #!/usr/bin/env bash 132 set -euo pipefail 133 base_url="https://api.github.com/licenses" 134 headers="Accept: application/vnd.github.drax-preview+json" 135 res=$(curl --silent --header $headers $base_url) 136 selection=$(echo "$res" | jq ".[].key" | tr -d '"' | gum choose --limit=1) 137 res=$(curl --silent --header $headers $base_url/$selection | jq ."body") 138 echo -e "$res" | tr -d '"' 139 140# Fetch and display public IP info 141[group('utilities')] 142[script] 143myip: 144 # /// script 145 # dependencies = [ 146 # "requests", 147 # ] 148 # /// 149 150 import json 151 import requests 152 153 if __name__ == "__main__": 154 KEY_COLOR = "\033[92m" 155 END_COLOR = "\033[0m" 156 157 response = requests.get("https://ipinfo.io", timeout=60) 158 json_data = json.loads(response.text) 159 160 print() 161 for item in json_data: 162 print(f"- {KEY_COLOR}{item.title():<16}{END_COLOR} {json_data[item]}") 163 164# vim: ts=4 sts=4 sw=4 et ft=just