Skip to content

Commit fe21bb1

Browse files
committed
Split out functions and add multi mode for tml
1 parent 8e9bd24 commit fe21bb1

6 files changed

Lines changed: 202 additions & 195 deletions

File tree

‎default/bash/fns/compression‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Compression
2+
compress() { tar -czf "${1%/}.tar.gz" "${1%/}"; }
3+
alias decompress="tar -xzf"

‎default/bash/fns/drives‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Write iso file to sd card
2+
iso2sd() {
3+
if [[ $# -lt 1 ]]; then
4+
echo "Usage: iso2sd <input_file> [output_device]"
5+
echo "Example: iso2sd ~/Downloads/ubuntu-25.04-desktop-amd64.iso /dev/sda"
6+
return 1
7+
fi
8+
9+
local iso="$1"
10+
local drive="$2"
11+
12+
if [[ -z $drive ]]; then
13+
local available_sds=$(lsblk -dpno NAME | grep -E '/dev/sd')
14+
15+
if [[ -z $available_sds ]]; then
16+
echo "No SD drives found and no drive specified"
17+
return 1
18+
fi
19+
20+
drive=$(omarchy-drive-select "$available_sds")
21+
22+
if [[ -z $drive ]]; then
23+
echo "No drive selected"
24+
return 1
25+
fi
26+
fi
27+
28+
sudo dd bs=4M status=progress oflag=sync if="$iso" of="$drive"
29+
sudo eject "$drive"
30+
}
31+
32+
# Format an entire drive for a single partition using exFAT
33+
format-drive() {
34+
if [ $# -ne 2 ]; then
35+
echo "Usage: format-drive <device> <name>"
36+
echo "Example: format-drive /dev/sda 'My Stuff'"
37+
echo -e "\nAvailable drives:"
38+
lsblk -d -o NAME -n | awk '{print "/dev/"$1}'
39+
else
40+
echo "WARNING: This will completely erase all data on $1 and label it '$2'."
41+
read -rp "Are you sure you want to continue? (y/N): " confirm
42+
43+
if [[ "$confirm" =~ ^[Yy]$ ]]; then
44+
sudo wipefs -a "$1"
45+
sudo dd if=/dev/zero of="$1" bs=1M count=100 status=progress
46+
sudo parted -s "$1" mklabel gpt
47+
sudo parted -s "$1" mkpart primary 1MiB 100%
48+
sudo parted -s "$1" set 1 msftdata on
49+
50+
partition="$([[ $1 == *"nvme"* ]] && echo "${1}p1" || echo "${1}1")"
51+
sudo partprobe "$1" || true
52+
sudo udevadm settle || true
53+
54+
sudo mkfs.exfat -n "$2" "$partition"
55+
56+
echo "Drive $1 formatted as exFAT and labeled '$2'."
57+
fi
58+
fi
59+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SSH Port Forwarding Functions
2+
fip() {
3+
[[ $# -lt 2 ]] && echo "Usage: fip <host> <port1> [port2] ..." && return 1
4+
local host="$1"
5+
shift
6+
for port in "$@"; do
7+
ssh -f -N -L "$port:localhost:$port" "$host" && echo "Forwarding localhost:$port -> $host:$port"
8+
done
9+
}
10+
11+
dip() {
12+
[[ $# -eq 0 ]] && echo "Usage: dip <port1> [port2] ..." && return 1
13+
for port in "$@"; do
14+
pkill -f "ssh.*-L $port:localhost:$port" && echo "Stopped forwarding port $port" || echo "No forwarding on port $port"
15+
done
16+
}
17+
18+
lip() {
19+
pgrep -af "ssh.*-L [0-9]+:localhost:[0-9]+" || echo "No active forwards"
20+
}

‎default/bash/fns/tmux‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Create a tmux layout for dev with editor, ai, and terminal
2+
tml() {
3+
[[ -z $TMUX ]] && { echo "You must start tmux to use tml."; return 1; }
4+
5+
local current_dir="${PWD}"
6+
local editor_pane ai_pane
7+
local ai="$1"
8+
9+
# Use TMUX_PANE for the pane we're running in (stable even if active window changes)
10+
editor_pane="$TMUX_PANE"
11+
12+
# Name the current window after the base directory name
13+
tmux rename-window -t "$editor_pane" "$(basename "$current_dir")"
14+
15+
# Split window vertically - top 85%, bottom 15% (target editor pane explicitly)
16+
tmux split-window -v -p 15 -t "$editor_pane" -c "$current_dir"
17+
18+
# Split editor pane horizontally - AI on right 30% (capture new pane ID directly)
19+
ai_pane=$(tmux split-window -h -p 30 -t "$editor_pane" -c "$current_dir" -P -F '#{pane_id}')
20+
21+
# Run ai in the right pane
22+
tmux send-keys -t "$ai_pane" "$ai" C-m
23+
24+
# Run nvim in the left pane
25+
tmux send-keys -t "$editor_pane" "$EDITOR ." C-m
26+
27+
# Select the nvim pane for focus
28+
tmux select-pane -t "$editor_pane"
29+
}
30+
31+
# Create a tml window per subdirectory in the current directory
32+
tmlm() {
33+
[[ -z $TMUX ]] && { echo "You must start tmux to use tmlm."; return 1; }
34+
35+
local ai="$1"
36+
local base_dir="$PWD"
37+
local first=true
38+
39+
# Rename the session to the current directory name (replace dots/colons which tmux disallows)
40+
tmux rename-session "$(basename "$base_dir" | tr '.:' '--')"
41+
42+
for dir in "$base_dir"/*/; do
43+
[[ -d $dir ]] || continue
44+
local dirpath="${dir%/}"
45+
46+
if $first; then
47+
# Reuse the current window for the first project
48+
tmux send-keys -t "$TMUX_PANE" "cd '$dirpath' && tml $ai" C-m
49+
first=false
50+
else
51+
local pane_id=$(tmux new-window -c "$dirpath" -P -F '#{pane_id}')
52+
tmux send-keys -t "$pane_id" "tml $ai" C-m
53+
fi
54+
done
55+
}
56+
57+
# Create a dev layout using tmux with editor, opencode, and terminal
58+
nic() {
59+
tml c
60+
}
61+
62+
# Create a dev layout using tmux with editor, claude, and terminal
63+
nicx() {
64+
tml cx
65+
}
66+
67+
# Create tml windows for each subdirectory using opencode
68+
nicm() {
69+
tmlm c
70+
}
71+
72+
# Create tml windows for each subdirectory using claude
73+
nicxm() {
74+
tmlm cx
75+
}

‎default/bash/fns/transcoding‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Transcode a video to a good-balance 1080p that's great for sharing online
2+
transcode-video-1080p() {
3+
ffmpeg -i $1 -vf scale=1920:1080 -c:v libx264 -preset fast -crf 23 -c:a copy ${1%.*}-1080p.mp4
4+
}
5+
6+
# Transcode a video to a good-balance 4K that's great for sharing online
7+
transcode-video-4K() {
8+
ffmpeg -i $1 -c:v libx265 -preset slow -crf 24 -c:a aac -b:a 192k ${1%.*}-optimized.mp4
9+
}
10+
11+
# Transcode any image to JPG image that's great for shrinking wallpapers
12+
img2jpg() {
13+
img="$1"
14+
shift
15+
16+
magick "$img" $@ -quality 95 -strip ${img%.*}-converted.jpg
17+
}
18+
19+
# Transcode any image to JPG image that's great for sharing online without being too big
20+
img2jpg-small() {
21+
img="$1"
22+
shift
23+
24+
magick "$img" $@ -resize 1080x\> -quality 95 -strip ${img%.*}-small.jpg
25+
}
26+
# Transcode any image to JPG image that's great for sharing online without being too big
27+
img2jpg-medium() {
28+
img="$1"
29+
shift
30+
31+
magick "$img" $@ -resize 1800x\> -quality 95 -strip ${img%.*}-medium.jpg
32+
}
33+
34+
# Transcode any image to compressed-but-lossless PNG
35+
img2png() {
36+
img="$1"
37+
shift
38+
39+
magick "$img" $@ -strip -define png:compression-filter=5 \
40+
-define png:compression-level=9 \
41+
-define png:compression-strategy=1 \
42+
-define png:exclude-chunk=all \
43+
"${img%.*}-optimized.png"
44+
}

0 commit comments

Comments
 (0)