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