Added bashrc aliases/functions and SSHFS automount utilities

This commit is contained in:
Jim Shepich III 2025-08-10 01:53:46 -04:00
commit b0ae7d6079
4 changed files with 128 additions and 0 deletions

15
babygram/bashrc Normal file
View File

@ -0,0 +1,15 @@
fn_lock() {
# Read fn_lock value directly in the if condition and invert it
if [ $(sudo cat /sys/devices/platform/lg-laptop/fn_lock) -eq 1 ]; then
sudo echo 0 > /sys/devices/platform/lg-laptop/fn_lock
else
sudo echo 1 > /sys/devices/platform/lg-laptop/fn_lock
fi
}
fix-alt(){
sudo xmodmap -e "keycode 64 = Alt_L Meta_L Alt_L Meta_L"
sudo xmodmap -e "keycode 108 = Alt_R Meta_R Alt_R Meta_R"
}
alias restart-audio="systemctl --user restart pipewire.service"

View File

@ -0,0 +1,9 @@
[Desktop Entry]
Name=SSHFS Automount
Exec=/opt/jimlab/sshfs-automount.sh
Type=Application
Icon=/usr/share/icons/Papirus/64x64@2x/places/folder-blue-private.svg
Comment=Automatically mount remote directories on login
Categories=Programming
Terminal=false
StartupNotify=true

41
bashrc Normal file
View File

@ -0,0 +1,41 @@
# List
alias l="ls -lhF --color=always"
# Long list
alias ll="ls -AlhF --color=always"
# Make and change directory
mcd() {
mkdir -p "$1" && cd "$1"
}
# Change directory list
cdl() {
cd "$1" && ls -lhF --color=always
}
# Change directory long list
cdll() {
cd "$1" && ls -AlhF --color=always
}
# Aliases for Python venv management.
alias activate="source .venv/bin/activate"
alias mkvenv="python3 -m venv .venv"
# Aliases for common podman/podman compose tasks.
alias pcupd="podman-compose up -d"
alias pcdown="podman-compose down"
alias pps="podman ps"
alias ccedit="nano container-compose.yaml"
# Enables an NGINX site by linking it from /etc/nginx/sites-available to /etc/nginx/sites-enabled.
nginx-enable(){
sudo ln -s "/etc/nginx/sites-available/$1.conf" "/etc/nginx/sites-enabled/$1.conf"
}
# Disables an NGINX site by removing the entry in /etc/nginx/sites-enabled.
nginx-disable(){
sudo rm "/etc/nginx/sites-enabled/$1.conf"
}

63
sshfs-automount.sh Executable file
View File

@ -0,0 +1,63 @@
#!/usr/bin/env bash
set -e pipefail
MAP_FILE="/etc/jimlab/sshfs.map"
SSHFS_BIN="/usr/bin/sshfs"
# Default options & user; override via env if you like.
SSHFS_OPTS="${SSHFS_OPTS:-delay_connect,reconnect,follow_symlinks,transform_symlinks}"
is_sshfs_mount() {
# true iff $1 is a real mountpoint and fstype looks like sshfs
local d="$1"
if ! mountpoint -q -- "$d"; then
return 1
fi
local fstype
fstype="$(findmnt -rn -o FSTYPE -T "$d" || true)"
[[ "$fstype" == "fuse.sshfs" || "$fstype" == sshfs ]]
}
mount_one() {
local remote="$1" # e.g., shrek:/path or jim@shrek:/path
local local_dir="$2"
# Ensure local mountpoint exists
mkdir -p -- "$local_dir"
# Skip if something already mounted there
if is_sshfs_mount "$local_dir"; then
echo "Already mounted: $local_dir (skipping)"
return 0
fi
echo "Mounting $remote -> $local_dir"
# Dont fail the whole script on a single mount error
if ! "$SSHFS_BIN" -o "$SSHFS_OPTS" "$remote" "$local_dir"; then
echo "WARN: Failed to mount $remote to $local_dir" >&2
return 0
fi
}
if [[ -f "$MAP_FILE" ]]; then
# Read map file: "<host[:port]>:/remote-path /local-path"
while IFS= read -r line; do
# Trim leading/trailing whitespace
line="${line#"${line%%[![:space:]]*}"}"
line="${line%"${line##*[![:space:]]}"}"
# Skip blanks & comments
[[ -z "$line" || "${line:0:1}" == "#" ]] && continue
# Expect two fields: remote local
# (Paths with spaces arent supported in this simple format)
read -r remote local_dir <<<"$line"
if [[ -z "${remote:-}" || -z "${local_dir:-}" ]]; then
echo "WARN: Bad line in $MAP_FILE: $line" >&2
continue
fi
mount_one "$remote" "$local_dir"
done < "$MAP_FILE"
else
echo "Map file $MAP_FILE does not exist."
fi