diff options
| author | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-24 04:19:59 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-24 04:19:59 +0530 |
| commit | 3a6e45ad18c519b21c9cadb2d374148647886b05 (patch) | |
| tree | c8ad94d5be285a770a319e6a6a6fdda6021b652a | |
| parent | 574b4e4651495ed3fb14ef53a00374782d45b378 (diff) | |
| download | home-manager-config-3a6e45ad18c519b21c9cadb2d374148647886b05.tar.gz home-manager-config-3a6e45ad18c519b21c9cadb2d374148647886b05.zip | |
refactor: ran newly configured formatter for the whole project
| -rw-r--r-- | .editorconfig | 6 | ||||
| -rw-r--r-- | .nvim.lua | 6 | ||||
| -rw-r--r-- | flake.lock | 23 | ||||
| -rw-r--r-- | flake.nix | 7 | ||||
| -rw-r--r-- | modules/communication/neomutt/neomutt-sync.sh | 20 | ||||
| -rw-r--r-- | modules/desktop/eww/bar/niri-status.lua | 154 | ||||
| -rw-r--r-- | modules/desktop/eww/bar/system-stats.lua | 12 | ||||
| -rw-r--r-- | modules/file-management/yazi/file-chooser.sh | 4 | ||||
| -rw-r--r-- | modules/media/screen-recording/screen-recording.sh | 49 | ||||
| -rw-r--r-- | modules/media/swayimg/init.lua | 20 | ||||
| -rw-r--r-- | modules/networking/usque/usque-warp.sh | 97 | ||||
| -rw-r--r-- | modules/office/calcurse/calcurse-sync.sh | 41 | ||||
| -rw-r--r-- | modules/security/gopass/gopass-sync-init.sh | 17 | ||||
| -rw-r--r-- | modules/security/gpg/gpg-backup.sh | 47 | ||||
| -rw-r--r-- | modules/security/ssh/gpg-ssh-key-load.sh | 33 | ||||
| -rw-r--r-- | modules/system/deep-clean/deep-clean.sh | 17 | ||||
| -rw-r--r-- | modules/system/nix-update/nix-update.sh | 83 | ||||
| -rw-r--r-- | modules/terminal/zsh/nix-aliases.sh | 6 |
18 files changed, 386 insertions, 256 deletions
diff --git a/.editorconfig b/.editorconfig index a4ce5a7..5731e2a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,7 +5,11 @@ root = true indent_style = space indent_size = 2 -[*.sh] +[*.{sh,zsh}] +indent_style = space +indent_size = 2 + +[*.lua] indent_style = space indent_size = 2 @@ -1,6 +1,6 @@ ---@diagnostic disable-next-line: undefined-global vim.lsp.enable({ - 'lua_ls', - 'nixd', - 'bash_ls' + "lua_ls", + "nixd", + "bash_ls", }) @@ -133,7 +133,8 @@ "git-hooks": "git-hooks", "home-manager": "home-manager", "nixpkgs": "nixpkgs", - "nixvim": "nixvim" + "nixvim": "nixvim", + "treefmt-nix": "treefmt-nix" } }, "systems": { @@ -152,6 +153,26 @@ "repo": "default", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1786901030, + "narHash": "sha256-WSFCsDSE5ffgD2MqzkM2CYjeFiKhRF/dJUN8uedb6YE=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "27b3b12a8e6375f28ebe122f07d230ca5459bbfa", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", @@ -60,6 +60,13 @@ indent_size = 2; }; }; + settings.formatter.stylua.excludes = [ + # Anonymous function fragments embedded into nixvim options via + # builtins.readFile are not complete Lua chunks, so stylua cannot + # parse them. + "modules/development/nixvim/plugins/gitsigns/on-attach.lua" + "modules/development/nixvim/plugins/lsp/open-diagnostic-float.lua" + ]; }; preCommitCheck = git-hooks.lib.${system}.run { diff --git a/modules/communication/neomutt/neomutt-sync.sh b/modules/communication/neomutt/neomutt-sync.sh index ff43039..6ecb14e 100644 --- a/modules/communication/neomutt/neomutt-sync.sh +++ b/modules/communication/neomutt/neomutt-sync.sh @@ -25,7 +25,7 @@ fi CHANNEL="$1" -cat <<'EOF' > "$DIALOGRC" +cat <<'EOF' >"$DIALOGRC" use_shadow = ON use_colors = ON screen_color = (WHITE,BLACK,OFF) @@ -48,7 +48,7 @@ EOF ( printf "XXX\n0\nSyncing: %s...\nXXX\n" "$CHANNEL" - mbsync -c "$MBSYNCRC" "$CHANNEL" > "$MBSYNC_LOG" 2>&1 & + mbsync -c "$MBSYNCRC" "$CHANNEL" >"$MBSYNC_LOG" 2>&1 & PID=$! # Keep the gauge alive while mbsync runs. @@ -60,19 +60,19 @@ EOF wait "$PID" MBSYNC_STATUS=$? - if (( MBSYNC_STATUS != 0 )); then + if ((MBSYNC_STATUS != 0)); then printf "XXX\n100\nSync failed: %s\nXXX\n" "$CHANNEL" exit "$MBSYNC_STATUS" fi printf "XXX\n90\nIndexing new mail with notmuch...\nXXX\n" - notmuch new --quiet > "$NOTMUCH_LOG" 2>&1 + notmuch new --quiet >"$NOTMUCH_LOG" 2>&1 NOTMUCH_STATUS=$? printf "XXX\n100\nDone.\nXXX\n" - if (( NOTMUCH_STATUS != 0 )); then + if ((NOTMUCH_STATUS != 0)); then exit "$NOTMUCH_STATUS" fi ) | dialog --title "$TITLE" --gauge "Initializing..." 8 80 0 @@ -80,16 +80,16 @@ EOF STATUS=${PIPESTATUS[0]} MBSYNC_OUT=$( - tr '\n' ' ' < "$MBSYNC_LOG" | - sed 's/ */ /g' + tr '\n' ' ' <"$MBSYNC_LOG" | + sed 's/ */ /g' ) NOTMUCH_OUT=$( - tr '\n' ' ' < "$NOTMUCH_LOG" | - sed 's/ */ /g' + tr '\n' ' ' <"$NOTMUCH_LOG" | + sed 's/ */ /g' ) -if (( STATUS == 0 )); then +if ((STATUS == 0)); then dialog \ --title "$TITLE" \ --msgbox "Done!\n\nChannel: $CHANNEL\n\nmbsync: ${MBSYNC_OUT:-OK}\n\nnotmuch: ${NOTMUCH_OUT:-OK}" \ diff --git a/modules/desktop/eww/bar/niri-status.lua b/modules/desktop/eww/bar/niri-status.lua index fdf88d2..cdeb89b 100644 --- a/modules/desktop/eww/bar/niri-status.lua +++ b/modules/desktop/eww/bar/niri-status.lua @@ -6,9 +6,9 @@ -- ran as two separate long-lived processes, each independently subscribed -- to niri's event-stream and, on every relevant event, independently -- re-fetched both `niri msg -j windows` and `niri msg -j workspaces` via a --- shelled-out io.popen. Combined that was up to 8 process spawns per single --- event across both scripts. Here there's one event-stream subscription, --- and one shared windows/workspaces fetch per event, significantly reducing +-- shelled-out io.popen. Combined that was up to 8 process spawns per single +-- event across both scripts. Here there's one event-stream subscription, +-- and one shared windows/workspaces fetch per event, significantly reducing -- the total number of spawned processes and resting children. -- -- The event-stream subscription is wrapped in a reconnect loop: if niri @@ -26,17 +26,33 @@ local DesktopAppInfo = nil do local lgi_ok, lgi = pcall(require, "lgi") if lgi_ok then - local gio_ok, gio = pcall(function() return lgi.Gio end) - if gio_ok then Gio = gio end + local gio_ok, gio = pcall(function() + return lgi.Gio + end) + if gio_ok then + Gio = gio + end - local giounix_ok, giounix = pcall(function() return lgi.GioUnix end) - if giounix_ok then GioUnix = giounix end + local giounix_ok, giounix = pcall(function() + return lgi.GioUnix + end) + if giounix_ok then + GioUnix = giounix + end - local gtk_ok, gtk = pcall(function() return lgi.Gtk end) - if gtk_ok then Gtk = gtk end + local gtk_ok, gtk = pcall(function() + return lgi.Gtk + end) + if gtk_ok then + Gtk = gtk + end - local gdk_ok, gdk = pcall(function() return lgi.Gdk end) - if gdk_ok then Gdk = gdk end + local gdk_ok, gdk = pcall(function() + return lgi.Gdk + end) + if gdk_ok then + Gdk = gdk + end DesktopAppInfo = (GioUnix and GioUnix.DesktopAppInfo) or (Gio and Gio.DesktopAppInfo) @@ -60,8 +76,12 @@ end local icon_cache = {} local function g_list_to_table(gl) - if gl == nil then return {} end - if type(gl) == "table" then return gl end + if gl == nil then + return {} + end + if type(gl) == "table" then + return gl + end local t = {} local cur = gl while cur do @@ -72,24 +92,32 @@ local function g_list_to_table(gl) end local function resolve_icon_path(app_id) - if not app_id or app_id == "" then return "" end - if icon_cache[app_id] then return icon_cache[app_id] end + if not app_id or app_id == "" then + return "" + end + if icon_cache[app_id] then + return icon_cache[app_id] + end local icon_path = "" if DesktopAppInfo and Gtk and icon_theme then local function try_desktop_app_info(desktop_id) local ok, info = pcall(DesktopAppInfo.new, desktop_id) - if ok and info then return info end + if ok and info then + return info + end return nil end local app_info = try_desktop_app_info(app_id .. ".desktop") - or try_desktop_app_info(string.lower(app_id) .. ".desktop") + or try_desktop_app_info(string.lower(app_id) .. ".desktop") if not app_info then local lc = string.lower(app_id) for _, info in ipairs(g_list_to_table(Gio.AppInfo.get_all())) do - local ok_wm, wm = pcall(function() return info:get_startup_wm_class() end) + local ok_wm, wm = pcall(function() + return info:get_startup_wm_class() + end) if ok_wm and wm and string.lower(wm) == lc then app_info = info break @@ -119,32 +147,47 @@ end -- Safely run niri msg without crashing due to luaposix version changes local function niri_json(command) local f = io.popen("niri msg -j " .. command .. " 2>/dev/null") - if not f then return nil end + if not f then + return nil + end local out = f:read("*a") f:close() local ok, decoded = pcall(cjson.decode, out) - if ok then return decoded end + if ok then + return decoded + end return nil end local function sanitize_utf8(s) - if type(s) ~= "string" or s == "" then return s end + if type(s) ~= "string" or s == "" then + return s + end local out = {} local i, n = 1, #s while i <= n do local c = s:byte(i) local len - if c < 0x80 then len = 1 - elseif c >= 0xC2 and c <= 0xDF then len = 2 - elseif c >= 0xE0 and c <= 0xEF then len = 3 - elseif c >= 0xF0 and c <= 0xF4 then len = 4 - else len = 0 end + if c < 0x80 then + len = 1 + elseif c >= 0xC2 and c <= 0xDF then + len = 2 + elseif c >= 0xE0 and c <= 0xEF then + len = 3 + elseif c >= 0xF0 and c <= 0xF4 then + len = 4 + else + len = 0 + end local valid = len > 0 and (i + len - 1 <= n) if valid then for k = 1, len - 1 do local cc = s:byte(i + k) - if not cc or cc < 0x80 or cc > 0xBF then valid = false break end + if not cc or cc < 0x80 or cc > 0xBF then + valid = false + break + end end end @@ -162,16 +205,24 @@ end local function window_sort_key(w) local layout = w.layout or {} local pos = layout.pos_in_scrolling_layout - if pos then return { 0, pos[1], pos[2] } end + if pos then + return { 0, pos[1], pos[2] } + end return { 1, w.id, 0 } end local function lt(a, b) for k = 1, math.max(#a, #b) do local x, y = a[k], b[k] - if y == nil then return false end - if x == nil then return true end - if x ~= y then return x < y end + if y == nil then + return false + end + if x == nil then + return true + end + if x ~= y then + return x < y + end end return false end @@ -217,20 +268,25 @@ local function build_state() } end -- Enforce JSON Array even if empty - if #active_windows_result == 0 then active_windows_result = empty_array end + if #active_windows_result == 0 then + active_windows_result = empty_array + end local ws_list = {} for _, ws in ipairs(workspaces_raw) do ws_list[#ws_list + 1] = ws end - table.sort(ws_list, function(a, b) return a.idx < b.idx end) + table.sort(ws_list, function(a, b) + return a.idx < b.idx + end) local workspaces_result = {} for _, ws in ipairs(ws_list) do local active_win = windows_by_id[ws.active_window_id] local app_id = (active_win and active_win.app_id) or "" - local ws_name = (type(ws.name) == "string" and ws.name ~= "userdata: NULL" and ws.name) or ("Workspace " .. tostring(ws.idx)) + local ws_name = (type(ws.name) == "string" and ws.name ~= "userdata: NULL" and ws.name) + or ("Workspace " .. tostring(ws.idx)) local ws_windows = {} for _, w in ipairs(windows_raw) do @@ -246,7 +302,12 @@ local function build_state() for idx, w in ipairs(ws_windows) do local w_app_id = sanitize_utf8(w.app_id or "") local w_title = sanitize_utf8(w.title or "") - lines[#lines + 1] = string.format("%d. %s: %s", idx, (w_app_id and w_app_id ~= "" and w_app_id) or "unknown", (w_title and w_title ~= "" and w_title) or "(untitled)") + lines[#lines + 1] = string.format( + "%d. %s: %s", + idx, + (w_app_id and w_app_id ~= "" and w_app_id) or "unknown", + (w_title and w_title ~= "" and w_title) or "(untitled)" + ) end workspaces_result[#workspaces_result + 1] = { @@ -258,7 +319,9 @@ local function build_state() } end -- Enforce JSON Array even if empty - if #workspaces_result == 0 then workspaces_result = empty_array end + if #workspaces_result == 0 then + workspaces_result = empty_array + end -- Output as a ROOT JSON OBJECT return { @@ -283,9 +346,14 @@ local function emit_state() end local RELEVANT_EVENTS = { - WindowOpenedOrChanged = true, WindowClosed = true, WindowFocusChanged = true, - WorkspaceActivated = true, WorkspacesChanged = true, WindowsChanged = true, - WorkspaceUrgencyChanged = true, WorkspaceActiveWindowChanged = true + WindowOpenedOrChanged = true, + WindowClosed = true, + WindowFocusChanged = true, + WorkspaceActivated = true, + WorkspacesChanged = true, + WindowsChanged = true, + WorkspaceUrgencyChanged = true, + WorkspaceActiveWindowChanged = true, } local function sleep(seconds) @@ -298,7 +366,9 @@ end -- or the socket isn't up yet). local function run_event_stream_session() local proc = io.popen("niri msg -j event-stream 2>/dev/null") - if not proc then return false end + if not proc then + return false + end local got_any_line = false for line in proc:lines() do @@ -306,7 +376,9 @@ local function run_event_stream_session() local ok, obj = pcall(cjson.decode, line) if ok and obj then local key = next(obj) - if RELEVANT_EVENTS[key] then emit_state() end + if RELEVANT_EVENTS[key] then + emit_state() + end end end proc:close() diff --git a/modules/desktop/eww/bar/system-stats.lua b/modules/desktop/eww/bar/system-stats.lua index 9571d26..b651e2d 100644 --- a/modules/desktop/eww/bar/system-stats.lua +++ b/modules/desktop/eww/bar/system-stats.lua @@ -313,12 +313,7 @@ local function build_cpu_tooltip(overall_pct, per_core_list, freq_mhz, load_avg) lines[#lines + 1] = string.format("Freq: %d MHz", freq_mhz) end if load_avg ~= nil then - lines[#lines + 1] = string.format( - "Load: %.2f %.2f %.2f", - load_avg[1], - load_avg[2], - load_avg[3] - ) + lines[#lines + 1] = string.format("Load: %.2f %.2f %.2f", load_avg[1], load_avg[2], load_avg[3]) end for i, pct in ipairs(per_core_list) do lines[#lines + 1] = string.format("Core %d: %d%%", i - 1, pct) @@ -682,10 +677,7 @@ local function spawn_inotify() end posix.close(r) posix.close(w) - local ok, err = posix.execp( - "inotifywait", - { "inotifywait", "-m", "-e", "modify", "/run/systemd/netif/state" } - ) + local ok, err = posix.execp("inotifywait", { "inotifywait", "-m", "-e", "modify", "/run/systemd/netif/state" }) if not ok then io.stderr:write("inotifywait: " .. tostring(err) .. "\n") os.exit(1) diff --git a/modules/file-management/yazi/file-chooser.sh b/modules/file-management/yazi/file-chooser.sh index bb5c7cc..34103ce 100644 --- a/modules/file-management/yazi/file-chooser.sh +++ b/modules/file-management/yazi/file-chooser.sh @@ -15,8 +15,8 @@ out="$5" # Pick directory vs single/multiple file if [ "$directory" = "1" ]; then - # Outputs the final working directory path on exit - exec yazi "$path" --cwd-file="$out" + # Outputs the final working directory path on exit + exec yazi "$path" --cwd-file="$out" else # Writes all selected file paths to the output file on exit exec yazi "$path" --chooser-file="$out" diff --git a/modules/media/screen-recording/screen-recording.sh b/modules/media/screen-recording/screen-recording.sh index 90cbc85..1afa239 100644 --- a/modules/media/screen-recording/screen-recording.sh +++ b/modules/media/screen-recording/screen-recording.sh @@ -5,36 +5,39 @@ OUT_DIR="$HOME/Videos/Recordings" mkdir -p "$OUT_DIR" -info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } -warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } +info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } +warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } error() { printf '\033[1;31m==> error:\033[0m %s\n' "$*" >&2; } -die() { error "$*"; exit 1; } +die() { + error "$*" + exit 1 +} # Argument parsing SELECT_MODE=false -while [[ "$#" -gt 0 ]]; do - case $1 in - -s|--select) SELECT_MODE=true ;; - esac - shift +while [[ $# -gt 0 ]]; do + case $1 in + -s | --select) SELECT_MODE=true ;; + esac + shift done # Geometry selection GEOMETRY="" if [ "$SELECT_MODE" = true ]; then - if command -v slurp >/dev/null 2>&1; then - info "Select a window or draw a box..." - GEOMETRY=$(slurp) - - if [ -z "$GEOMETRY" ]; then - info "Selection cancelled. Exiting." - exit 1 - fi - else - warn "slurp not found. Recording full screen..." - sleep 1 - fi + if command -v slurp >/dev/null 2>&1; then + info "Select a window or draw a box..." + GEOMETRY=$(slurp) + + if [ -z "$GEOMETRY" ]; then + info "Selection cancelled. Exiting." + exit 1 + fi + else + warn "slurp not found. Recording full screen..." + sleep 1 + fi fi # Start recording @@ -45,9 +48,9 @@ echo " Press 'q' in this terminal to stop." echo " File: $FILENAME" if [ -n "$GEOMETRY" ]; then - wf-recorder -g "$GEOMETRY" -f "$FILENAME" + wf-recorder -g "$GEOMETRY" -f "$FILENAME" else - wf-recorder -f "$FILENAME" + wf-recorder -f "$FILENAME" fi -info "Done! Video saved to $FILENAME"
\ No newline at end of file +info "Done! Video saved to $FILENAME" diff --git a/modules/media/swayimg/init.lua b/modules/media/swayimg/init.lua index 279d941..fccb126 100644 --- a/modules/media/swayimg/init.lua +++ b/modules/media/swayimg/init.lua @@ -20,11 +20,17 @@ swayimg.viewer.on_key("l", function() end) -- File switching -swayimg.viewer.on_key("n", function() swayimg.viewer.open("next") end) -swayimg.viewer.on_key("p", function() swayimg.viewer.open("prev") end) +swayimg.viewer.on_key("n", function() + swayimg.viewer.open("next") +end) +swayimg.viewer.on_key("p", function() + swayimg.viewer.open("prev") +end) -- Zoom controls -swayimg.viewer.on_key("equal", function() swayimg.viewer.reset() end) +swayimg.viewer.on_key("equal", function() + swayimg.viewer.reset() +end) swayimg.viewer.on_key("plus", function() swayimg.viewer.scale = swayimg.viewer.scale + 0.1 end) @@ -33,5 +39,9 @@ swayimg.viewer.on_key("minus", function() end) -- Actions -swayimg.viewer.on_key("q", function() swayimg.exit() end) -swayimg.viewer.on_key("f", function() swayimg.fullscreen = not swayimg.fullscreen end) +swayimg.viewer.on_key("q", function() + swayimg.exit() +end) +swayimg.viewer.on_key("f", function() + swayimg.fullscreen = not swayimg.fullscreen +end) diff --git a/modules/networking/usque/usque-warp.sh b/modules/networking/usque/usque-warp.sh index 700c857..1b70c12 100644 --- a/modules/networking/usque/usque-warp.sh +++ b/modules/networking/usque/usque-warp.sh @@ -4,10 +4,13 @@ set -euo pipefail -info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } -warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } +info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } +warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } error() { printf '\033[1;31m==> error:\033[0m %s\n' "$*" >&2; } -die() { error "$*"; exit 1; } +die() { + error "$*" + exit 1 +} CONFIG_DIR="$HOME/.cache/usque" CONFIG="$CONFIG_DIR/config.json" @@ -22,7 +25,7 @@ list_tun_ifaces() { } detect_iface() { - if [[ -f "$IFACE_FILE" ]]; then + if [[ -f $IFACE_FILE ]]; then cat "$IFACE_FILE" return fi @@ -30,10 +33,10 @@ detect_iface() { } is_running() { - [[ -f "$PID_FILE" ]] || return 1 + [[ -f $PID_FILE ]] || return 1 local pid pid=$(cat "$PID_FILE" 2>/dev/null || true) - [[ -n "$pid" ]] || return 1 + [[ -n $pid ]] || return 1 sudo kill -0 "$pid" 2>/dev/null } @@ -42,7 +45,7 @@ ensure_config() { mkdir -p "$CONFIG_DIR" info "Registering Cloudflare WARP account..." usque -c "$CONFIG" register < <(yes) - if [[ ! -f "$CONFIG" ]]; then + if [[ ! -f $CONFIG ]]; then die "Failed to create config file: $CONFIG" fi info "Config created successfully." @@ -60,7 +63,7 @@ remove_tun_default_routes() { connect() { sudo -v ensure_config - if [[ -f "$PID_FILE" ]]; then + if [[ -f $PID_FILE ]]; then OLD_PID=$(cat "$PID_FILE") if sudo kill -0 "$OLD_PID" 2>/dev/null; then die "usque-warp is already running (PID $OLD_PID)" @@ -72,10 +75,10 @@ connect() { info "Saving current default route..." DEFAULT_ROUTE=$(ip route show default | grep -vE 'dev tun[0-9]+' | head -n1) - if [[ -z "$DEFAULT_ROUTE" ]]; then + if [[ -z $DEFAULT_ROUTE ]]; then die "Could not determine current default route" fi - echo "$DEFAULT_ROUTE" > "$STATE_FILE" + echo "$DEFAULT_ROUTE" >"$STATE_FILE" info "Recording pre-existing tun interfaces..." BEFORE_IFACES=$(list_tun_ifaces) @@ -92,12 +95,12 @@ connect() { MASQUE_IP="" for _ in {1..30}; do MASQUE_IP=$(grep -oP 'MASQUE connection to \K[0-9.]+(?=:443)' "$LOG_FILE" 2>/dev/null || true) - if [[ -n "$MASQUE_IP" ]]; then + if [[ -n $MASQUE_IP ]]; then break fi sleep 1 done - if [[ -z "$MASQUE_IP" ]]; then + if [[ -z $MASQUE_IP ]]; then error "Failed to detect MASQUE endpoint" sudo kill "$(cat "$PID_FILE")" 2>/dev/null || true rm -f "$PID_FILE" @@ -109,24 +112,24 @@ connect() { for _ in {1..30}; do AFTER_IFACES=$(list_tun_ifaces) TUN_DEV=$(comm -13 <(echo "$BEFORE_IFACES" | sort) <(echo "$AFTER_IFACES" | sort) | head -n1) - [[ -n "$TUN_DEV" ]] && break + [[ -n $TUN_DEV ]] && break sleep 1 done - if [[ -z "$TUN_DEV" ]]; then + if [[ -z $TUN_DEV ]]; then error "Failed to detect usque interface" sudo kill "$(cat "$PID_FILE")" 2>/dev/null || true rm -f "$PID_FILE" exit 1 fi - echo "$TUN_DEV" > "$IFACE_FILE" + echo "$TUN_DEV" >"$IFACE_FILE" info "Detected interface: $TUN_DEV" GATEWAY=$(echo "$DEFAULT_ROUTE" | awk '{for(i=1;i<=NF;i++) if($i=="via") print $(i+1)}') INTERFACE=$(echo "$DEFAULT_ROUTE" | awk '{for(i=1;i<=NF;i++) if($i=="dev") print $(i+1)}') - if [[ -z "$GATEWAY" || -z "$INTERFACE" ]]; then + if [[ -z $GATEWAY || -z $INTERFACE ]]; then die "Cannot determine gateway/interface" fi - echo "MASQUE_IP=$MASQUE_IP GATEWAY=$GATEWAY INTERFACE=$INTERFACE" >> "$STATE_FILE" + echo "MASQUE_IP=$MASQUE_IP GATEWAY=$GATEWAY INTERFACE=$INTERFACE" >>"$STATE_FILE" info "Allowing MASQUE endpoint outside tunnel..." sudo ip route replace \ @@ -146,7 +149,7 @@ disconnect() { sudo -v info "Disconnecting..." local dev - if [[ -f "$IFACE_FILE" ]]; then + if [[ -f $IFACE_FILE ]]; then dev=$(cat "$IFACE_FILE") else dev=$(list_tun_ifaces | head -n1) @@ -155,7 +158,7 @@ disconnect() { # Kill usque FIRST so the kernel tears down tun0 (and every route # bound to it) as a single atomic operation, instead of us racing # it by pulling routes out from under a device that's still up. - if [[ -f "$PID_FILE" ]]; then + if [[ -f $PID_FILE ]]; then PID=$(cat "$PID_FILE") if sudo kill -0 "$PID" 2>/dev/null; then info "Stopping usque..." @@ -174,7 +177,7 @@ disconnect() { # Give the kernel a moment to tear the tunnel device down; only touch # routes manually if it is not disappearing on its own. - if [[ -n "${dev:-}" ]]; then + if [[ -n ${dev:-} ]]; then info "Waiting for tunnel interface to go down..." for _ in {1..25}; do list_tun_ifaces | grep -qx "$dev" || break @@ -187,9 +190,9 @@ disconnect() { fi fi - if [[ -f "$STATE_FILE" ]]; then + if [[ -f $STATE_FILE ]]; then MASQUE_IP=$(grep -oP 'MASQUE_IP=\K[0-9.]+' "$STATE_FILE" || true) - if [[ -n "$MASQUE_IP" ]]; then + if [[ -n $MASQUE_IP ]]; then info "Removing MASQUE route: $MASQUE_IP" sudo ip route del "$MASQUE_IP" 2>/dev/null || true fi @@ -197,10 +200,10 @@ disconnect() { # Explicitly restore the pre-connect default route rather than # assuming it's still intact. 'replace' is idempotent. ORIGINAL_DEFAULT=$(head -n1 "$STATE_FILE") - if [[ "$ORIGINAL_DEFAULT" == default* ]]; then + if [[ $ORIGINAL_DEFAULT == default* ]]; then info "Restoring original default route..." - sudo ip route replace "$ORIGINAL_DEFAULT" \ - || warn "could not restore original default route" + sudo ip route replace "$ORIGINAL_DEFAULT" || + warn "could not restore original default route" fi rm -f "$STATE_FILE" @@ -215,11 +218,11 @@ status() { iface=$(detect_iface) is_running && running=true - if [[ -n "$iface" && "$running" == true ]]; then + if [[ -n $iface && $running == true ]]; then printf '{"text":"%s","tooltip":"WARP connected via %s","class":"connected"}\n' "$iface" "$iface" - elif [[ -n "$iface" ]]; then + elif [[ -n $iface ]]; then printf '{"text":"%s","tooltip":"Interface %s up, but usque-warp process not tracked","class":"connected"}\n' "$iface" "$iface" - elif [[ "$running" == true ]]; then + elif [[ $running == true ]]; then printf '{"text":"connecting","tooltip":"usque starting...","class":"connecting"}\n' else printf '{"text":"","tooltip":"WARP disconnected","class":"disconnected"}\n' @@ -227,22 +230,22 @@ status() { } case "${1:-}" in - connect) - connect - ;; - disconnect) - disconnect - ;; - status) - status - ;; - *) - echo "Usage: $0 <connect|disconnect|status>" - echo "" - echo "Commands:" - echo " connect Start the WARP tunnel" - echo " disconnect Stop the WARP tunnel and restore routes" - echo " status Print Waybar status JSON" - exit 1 - ;; -esac
\ No newline at end of file +connect) + connect + ;; +disconnect) + disconnect + ;; +status) + status + ;; +*) + echo "Usage: $0 <connect|disconnect|status>" + echo "" + echo "Commands:" + echo " connect Start the WARP tunnel" + echo " disconnect Stop the WARP tunnel and restore routes" + echo " status Print Waybar status JSON" + exit 1 + ;; +esac diff --git a/modules/office/calcurse/calcurse-sync.sh b/modules/office/calcurse/calcurse-sync.sh index fafbc6e..737ebfb 100644 --- a/modules/office/calcurse/calcurse-sync.sh +++ b/modules/office/calcurse/calcurse-sync.sh @@ -24,16 +24,19 @@ set -euo pipefail DATA_DIR="${CALCURSE_DATA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/calcurse}" BRANCH="master" -SYNC_TIMEOUT="8" # seconds before a network op gives up +SYNC_TIMEOUT="8" # seconds before a network op gives up -info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } -warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } +info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } +warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } error() { printf '\033[1;31m==> error:\033[0m %s\n' "$*" >&2; } -die() { error "$*"; exit 1; } +die() { + error "$*" + exit 1 +} require_git() { - command -v git >/dev/null 2>&1 \ - || die "git is not installed or not on PATH. Install it and try again." + command -v git >/dev/null 2>&1 || + die "git is not installed or not on PATH. Install it and try again." } require_data_dir() { @@ -69,10 +72,10 @@ readable_timestamp() { day=$(date +%-d) case "$day" in - 1|21|31) suffix="st" ;; - 2|22) suffix="nd" ;; - 3|23) suffix="rd" ;; - *) suffix="th" ;; + 1 | 21 | 31) suffix="st" ;; + 2 | 22) suffix="nd" ;; + 3 | 23) suffix="rd" ;; + *) suffix="th" ;; esac month_year=$(date +"%B, %Y") @@ -94,7 +97,7 @@ do_init() { # calcurse sometimes drops lock/swap files in here; keep them out of git if [ ! -e "$DATA_DIR/.gitignore" ]; then - cat > "$DATA_DIR/.gitignore" <<'EOF' + cat >"$DATA_DIR/.gitignore" <<'EOF' *.lock *.swp EOF @@ -236,7 +239,7 @@ cmd_pull() { status=$? if [ "$status" -eq 124 ]; then warn "Pull timed out after ${SYNC_TIMEOUT}s — continuing with local data." - warn "Set \$CALCURSE_SYNC_TIMEOUT to a higher value if your connection" + warn 'Set $CALCURSE_SYNC_TIMEOUT to a higher value if your connection' warn "is just slow, not down." return 0 fi @@ -265,13 +268,13 @@ main() { shift || true case "$sub" in - init) cmd_init "$@" ;; - sync) cmd_sync "$@" ;; - pull) cmd_pull "$@" ;; - status) cmd_status "$@" ;; - remote) cmd_remote "$@" ;; - help|-h|--help) cmd_help ;; - *) die "unknown command: $sub (try 'calcurse-sync help')" ;; + init) cmd_init "$@" ;; + sync) cmd_sync "$@" ;; + pull) cmd_pull "$@" ;; + status) cmd_status "$@" ;; + remote) cmd_remote "$@" ;; + help | -h | --help) cmd_help ;; + *) die "unknown command: $sub (try 'calcurse-sync help')" ;; esac } diff --git a/modules/security/gopass/gopass-sync-init.sh b/modules/security/gopass/gopass-sync-init.sh index 5d5e423..8250458 100644 --- a/modules/security/gopass/gopass-sync-init.sh +++ b/modules/security/gopass/gopass-sync-init.sh @@ -8,24 +8,27 @@ STORE_DIR="@@PASSWORD_STORE_DIR@@" -info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } -warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } +info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } +warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } error() { printf '\033[1;31m==> error:\033[0m %s\n' "$*" >&2; } -die() { error "$*"; exit 1; } +die() { + error "$*" + exit 1 +} mkdir -p "$STORE_DIR" cd "$STORE_DIR" || die "Failed to enter $STORE_DIR" # Check if the directory is already a git repository; initialize if not if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then - info "Initializing git repository in $STORE_DIR..." - git init + info "Initializing git repository in $STORE_DIR..." + git init fi # Check if the remote 'origin' is set; add it if not if ! git remote | grep -q "^origin$"; then - info "Adding remote origin..." - git remote add origin "@@REMOTE_REPO_URL@@" + info "Adding remote origin..." + git remote add origin "@@REMOTE_REPO_URL@@" fi info "Password store git setup complete." diff --git a/modules/security/gpg/gpg-backup.sh b/modules/security/gpg/gpg-backup.sh index 685c4a3..41c7524 100644 --- a/modules/security/gpg/gpg-backup.sh +++ b/modules/security/gpg/gpg-backup.sh @@ -4,15 +4,18 @@ set -euo pipefail -info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } -warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } +info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } +warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } error() { printf '\033[1;31m==> error:\033[0m %s\n' "$*" >&2; } -die() { error "$*"; exit 1; } +die() { + error "$*" + exit 1 +} WORKDIR="$(mktemp -d)" cleanup() { - if [[ -d "$WORKDIR" ]]; then + if [[ -d $WORKDIR ]]; then find "$WORKDIR" -type f -exec shred -u -z {} \; 2>/dev/null || true rm -rf "$WORKDIR" fi @@ -31,21 +34,21 @@ usage() { do_export() { local outfile="$1" - if [[ -e "$outfile" ]]; then + if [[ -e $outfile ]]; then die "Refusing to overwrite existing file: $outfile" fi info "Exporting public keys..." - gpg --export --armor > "$WORKDIR/public-keys.asc" + gpg --export --armor >"$WORKDIR/public-keys.asc" info "Exporting secret keys..." - gpg --export-secret-keys --armor > "$WORKDIR/secret-keys.asc" + gpg --export-secret-keys --armor >"$WORKDIR/secret-keys.asc" info "Exporting secret subkeys (if any)..." - gpg --export-secret-subkeys --armor > "$WORKDIR/secret-subkeys.asc" || true + gpg --export-secret-subkeys --armor >"$WORKDIR/secret-subkeys.asc" || true info "Exporting owner trust database..." - gpg --export-ownertrust > "$WORKDIR/ownertrust.txt" + gpg --export-ownertrust >"$WORKDIR/ownertrust.txt" info "Exporting revocation certificates..." mkdir -p "$WORKDIR/revocation-certs" @@ -73,7 +76,7 @@ do_export() { "$WORKDIR/gpg-full-backup.tar" info "Verifying: attempting decryption to confirm it works..." - if gpg --decrypt "$outfile" > "$WORKDIR/verify.tar" 2>/dev/null; then + if gpg --decrypt "$outfile" >"$WORKDIR/verify.tar" 2>/dev/null; then if cmp -s "$WORKDIR/gpg-full-backup.tar" "$WORKDIR/verify.tar"; then info "Verification succeeded: backup decrypts correctly." else @@ -94,14 +97,14 @@ do_export() { do_import() { local infile="$1" - if [[ ! -f "$infile" ]]; then + if [[ ! -f $infile ]]; then die "File not found: $infile" fi info "Decrypting $infile ..." echo " You will be prompted for the backup's passphrase." echo " Note: this may take a while due to the high S2K iteration count." - gpg --decrypt "$infile" > "$WORKDIR/gpg-full-backup.tar" + gpg --decrypt "$infile" >"$WORKDIR/gpg-full-backup.tar" info "Extracting archive..." tar -C "$WORKDIR" -xf "$WORKDIR/gpg-full-backup.tar" @@ -143,13 +146,13 @@ command="$1" filename="$2" case "$command" in - export) - do_export "$filename" - ;; - import) - do_import "$filename" - ;; - *) - usage - ;; -esac
\ No newline at end of file +export) + do_export "$filename" + ;; +import) + do_import "$filename" + ;; +*) + usage + ;; +esac diff --git a/modules/security/ssh/gpg-ssh-key-load.sh b/modules/security/ssh/gpg-ssh-key-load.sh index 02dda1d..b9567f8 100644 --- a/modules/security/ssh/gpg-ssh-key-load.sh +++ b/modules/security/ssh/gpg-ssh-key-load.sh @@ -15,10 +15,13 @@ export GNUPGHOME="@@GNUPGHOME@@" GOPASS_SSH_KEY="@@GOPASS_SSH_KEY@@" -info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } -warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } +info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } +warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } error() { printf '\033[1;31m==> error:\033[0m %s\n' "$*" >&2; } -die() { error "$*"; exit 1; } +die() { + error "$*" + exit 1 +} usage() { cat <<EOF @@ -34,15 +37,15 @@ EOF while [[ $# -gt 0 ]]; do case "$1" in - --help | -h) - usage - exit 0 - ;; - *) - error "Unknown option: $1" - usage - exit 1 - ;; + --help | -h) + usage + exit 0 + ;; + *) + error "Unknown option: $1" + usage + exit 1 + ;; esac done @@ -60,14 +63,14 @@ if ssh-add -l 2>/dev/null | grep -qE "(ED25519|RSA|ECDSA)"; then exit 0 fi -if ! gopass show -o "$GOPASS_SSH_KEY" > /dev/null 2>&1; then +if ! gopass show -o "$GOPASS_SSH_KEY" >/dev/null 2>&1; then die "no gopass entry $GOPASS_SSH_KEY" fi tmpdir=$(mktemp -d) trap 'rm -rf "$tmpdir"' EXIT keyfile="$tmpdir/key" -gopass show -o "$GOPASS_SSH_KEY" > "$keyfile" 2>/dev/null +gopass show -o "$GOPASS_SSH_KEY" >"$keyfile" 2>/dev/null chmod 600 "$keyfile" passphrase=$(gopass show -o "$GOPASS_SSH_KEY/passphrase" 2>/dev/null || true) @@ -82,4 +85,4 @@ if ! timeout 60 ssh-add "$keyfile"; then exit 1 fi -info "SSH key loaded into gpg-agent."
\ No newline at end of file +info "SSH key loaded into gpg-agent." diff --git a/modules/system/deep-clean/deep-clean.sh b/modules/system/deep-clean/deep-clean.sh index f22a620..025366a 100644 --- a/modules/system/deep-clean/deep-clean.sh +++ b/modules/system/deep-clean/deep-clean.sh @@ -4,10 +4,13 @@ set -euo pipefail -info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } -warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } +info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } +warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } error() { printf '\033[1;31m==> error:\033[0m %s\n' "$*" >&2; } -die() { error "$*"; exit 1; } +die() { + error "$*" + exit 1 +} info "Starting Nix Deep Clean (keeping only current generations)" @@ -20,9 +23,9 @@ info "Removing old NixOS system generations..." sudo nix-env -p /nix/var/nix/profiles/system --delete-generations +1 info "Removing old Home Manager generations..." -if command -v home-manager &> /dev/null; then - home-manager generations | \ - awk 'NR>1 {print $1}' | \ +if command -v home-manager &>/dev/null; then + home-manager generations | + awk 'NR>1 {print $1}' | xargs -r home-manager remove-generations fi @@ -39,4 +42,4 @@ nix-collect-garbage -d info "Optimising Nix store..." nix store optimise -info "Cleanup Complete."
\ No newline at end of file +info "Cleanup Complete." diff --git a/modules/system/nix-update/nix-update.sh b/modules/system/nix-update/nix-update.sh index 79718fd..6ceaaa3 100644 --- a/modules/system/nix-update/nix-update.sh +++ b/modules/system/nix-update/nix-update.sh @@ -3,10 +3,13 @@ set -euo pipefail -info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } -warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } +info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } +warn() { printf '\033[1;33m==> warning:\033[0m %s\n' "$*" >&2; } error() { printf '\033[1;31m==> error:\033[0m %s\n' "$*" >&2; } -die() { error "$*"; exit 1; } +die() { + error "$*" + exit 1 +} HOME_MANAGER_CONFIG_DIR="$HOME/.config/home-manager" NIXOS_CONFIG_DIR="/etc/nixos" @@ -31,33 +34,33 @@ print_usage() { parse_command_line_arguments() { while [[ $# -gt 0 ]]; do case "$1" in - home-manager | nixos | both) - if [[ -n "$UPDATE_TARGET" ]]; then - error "only one target allowed" - print_usage - fi - UPDATE_TARGET="$1" - shift - ;; - --only-flake) - ONLY_UPDATE_FLAKE_INPUTS=true - shift - ;; - --only-switch) - ONLY_SWITCH_CONFIGURATION=true - shift - ;; - -h | --help) - print_usage - ;; - *) - error "unknown option '$1'" + home-manager | nixos | both) + if [[ -n $UPDATE_TARGET ]]; then + error "only one target allowed" print_usage - ;; + fi + UPDATE_TARGET="$1" + shift + ;; + --only-flake) + ONLY_UPDATE_FLAKE_INPUTS=true + shift + ;; + --only-switch) + ONLY_SWITCH_CONFIGURATION=true + shift + ;; + -h | --help) + print_usage + ;; + *) + error "unknown option '$1'" + print_usage + ;; esac done - if [[ -z "$UPDATE_TARGET" ]]; then + if [[ -z $UPDATE_TARGET ]]; then error "no target specified" print_usage fi @@ -72,12 +75,12 @@ update_home_manager_configuration() { trap 'git rm --cached users/arpit/private.nix >/dev/null 2>&1 || true' EXIT INT TERM HUP - if [[ "$ONLY_SWITCH_CONFIGURATION" == false ]]; then + if [[ $ONLY_SWITCH_CONFIGURATION == false ]]; then info "Running nix flake update..." nix flake update fi - if [[ "$ONLY_UPDATE_FLAKE_INPUTS" == false ]]; then + if [[ $ONLY_UPDATE_FLAKE_INPUTS == false ]]; then info "Running home-manager switch..." home-manager switch --flake "$HOME_MANAGER_CONFIG_DIR#arpit" fi @@ -100,12 +103,12 @@ update_nixos_configuration() { trap 'git rm --cached hardware-configuration.nix >/dev/null 2>&1 || true' EXIT INT TERM HUP - if [[ "$ONLY_SWITCH_CONFIGURATION" == false ]]; then + if [[ $ONLY_SWITCH_CONFIGURATION == false ]]; then info "Running nix flake update..." nix flake update fi - if [[ "$ONLY_UPDATE_FLAKE_INPUTS" == false ]]; then + if [[ $ONLY_UPDATE_FLAKE_INPUTS == false ]]; then info "Running nixos-rebuild switch..." sudo nixos-rebuild switch fi @@ -121,14 +124,14 @@ update_nixos_configuration() { parse_command_line_arguments "$@" case "$UPDATE_TARGET" in - home-manager) - update_home_manager_configuration - ;; - nixos) - update_nixos_configuration - ;; - both) - update_nixos_configuration - update_home_manager_configuration - ;; +home-manager) + update_home_manager_configuration + ;; +nixos) + update_nixos_configuration + ;; +both) + update_nixos_configuration + update_home_manager_configuration + ;; esac diff --git a/modules/terminal/zsh/nix-aliases.sh b/modules/terminal/zsh/nix-aliases.sh index 1c07d3a..671bc4c 100644 --- a/modules/terminal/zsh/nix-aliases.sh +++ b/modules/terminal/zsh/nix-aliases.sh @@ -1,7 +1,7 @@ # Wrappers for nix-shell and nix develop that auto-start $SHELL nix-shell() { for arg in "$@"; do - if [[ "$arg" == "--run" || "$arg" == "--command" ]]; then + if [[ $arg == "--run" || $arg == "--command" ]]; then command nix-shell "$@" return fi @@ -11,11 +11,11 @@ nix-shell() { } nix() { - if [[ "$1" == "develop" ]]; then + if [[ $1 == "develop" ]]; then local args=("${@:2}") for arg in "${args[@]}"; do - if [[ "$arg" == "-c" || "$arg" == "--command" ]]; then + if [[ $arg == "-c" || $arg == "--command" ]]; then command nix "$@" return fi |
