summaryrefslogtreecommitdiff
path: root/bash/.bash_aliases
blob: 0eafcad2fc456d9af32d76c2234aa83264075e2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
alias cp='cp -iv'
alias rm='rm -iv'
alias mv='mv -iv'

# Git
alias lg='lazygit'
alias gs='git status'
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gd='git diff'
alias go='git checkout'
alias gl='git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'

# Nixos
alias ras='sudo nixos-rebuild switch --flake .#'

# Tmux
tm() {
  # Handle specific session attachment (standard behavior).
  if [ -n "$1" ]; then
    tmux attach-session -t "$1" 2>/dev/null || tmux new-session -s "$1"
    return
  fi

  # If no tmux server is running at all.
  if ! tmux has-session 2>/dev/null; then
    # Start a dummy session in the background to kickstart the server.
    tmux new-session -d -s "init"

    # Trigger the restore script.
    RESURRECT_SCRIPT="$HOME/.config/tmux/plugins/tmux-resurrect/scripts/restore.sh"

    if [ -f "$RESURRECT_SCRIPT" ]; then
      tmux run-shell "$RESURRECT_SCRIPT"
      # Kill the dummy session once restored.
      tmux kill-session -t "init" 2>/dev/null
    fi
  fi

  # Attach and show the tree.
  tmux attach-session -t "main" 2>/dev/null || tmux attach-session \; choose-tree -sZ -O name
}

# Edit NixOS Sops secret files.
se() {
    local SYSTEM=$1
    local REPO_ROOT="$HOME/.nixos"
    local SECRET_PATH="$REPO_ROOT/systems/$SYSTEM/secrets/secrets.yaml"

    if [ -z "$SYSTEM" ]; then
        echo "Usage: se <system_name> (e.g., se suliman)"
        return 1
    fi

    if [ ! -f "$SECRET_PATH" ]; then
        echo "Error: Secret file not found at $SECRET_PATH"
        echo "Creating new secret file for $SYSTEM..."
        mkdir -p "$(dirname "$SECRET_PATH")"
    fi

    nix shell nixpkgs#sops -c sops "$SECRET_PATH"
}