commit b0ae7d6079ef4931f75e818bc22a678ca59045d1 Author: Jim Shepich III Date: Sun Aug 10 01:53:46 2025 -0400 Added bashrc aliases/functions and SSHFS automount utilities diff --git a/babygram/bashrc b/babygram/bashrc new file mode 100644 index 0000000..42f066a --- /dev/null +++ b/babygram/bashrc @@ -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" diff --git a/babygram/sshfs-automount.desktop b/babygram/sshfs-automount.desktop new file mode 100644 index 0000000..9a566ab --- /dev/null +++ b/babygram/sshfs-automount.desktop @@ -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 diff --git a/bashrc b/bashrc new file mode 100644 index 0000000..3acc108 --- /dev/null +++ b/bashrc @@ -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" +} diff --git a/sshfs-automount.sh b/sshfs-automount.sh new file mode 100755 index 0000000..78353e2 --- /dev/null +++ b/sshfs-automount.sh @@ -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" + # Don’t 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: ":/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 aren’t 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