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# Create a .tar.gz archive from {{dir}} 78[group('utilities')] 79create-archive dir: 80 #!/usr/bin/env bash 81 set -eu 82 DIR_NAME={{ dir }} 83 archive_name="${DIR_NAME}-$(date '+%Y%m%d').tar.gz" 84 tar cvfz "$archive_name" "$DIR_NAME" 85 echo "Created archive $archive_name" 86 87# Get the day of the week a given date falls on 88[group('utilities')] 89dayofweek year month day: 90 #!/usr/bin/python3 91 import sys 92 from datetime import datetime 93 94 if __name__ == "__main__": 95 if len(sys.argv) != 4: 96 print("Usage: dayofweek <year> <month> <day>") 97 exit(1) 98 else: 99 print(datetime(int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])).strftime("%A")) 100 101# Download an open source license 102[group('utilities')] 103get-license: 104 #!/usr/bin/env bash 105 set -euo pipefail 106 base_url="https://api.github.com/licenses" 107 headers="Accept: application/vnd.github.drax-preview+json" 108 res=$(curl --silent --header $headers $base_url) 109 selection=$(echo "$res" | jq ".[].key" | tr -d '"' | gum choose --limit=1) 110 res=$(curl --silent --header $headers $base_url/$selection | jq ."body") 111 echo -e "$res" | tr -d '"' 112 113# Fetch and display public IP info 114[group('utilities')] 115[script] 116myip: 117 # /// script 118 # dependencies = [ 119 # "requests", 120 # ] 121 # /// 122 123 import json 124 import requests 125 126 if __name__ == "__main__": 127 KEY_COLOR = "\033[92m" 128 END_COLOR = "\033[0m" 129 130 response = requests.get("https://ipinfo.io", timeout=60) 131 json_data = json.loads(response.text) 132 133 print() 134 for item in json_data: 135 print(f"- {KEY_COLOR}{item.title():<16}{END_COLOR} {json_data[item]}") 136 137# vim: ts=4 sts=4 sw=4 et ft=just