-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bash_aliases
More file actions
executable file
·127 lines (110 loc) · 3.4 KB
/
.bash_aliases
File metadata and controls
executable file
·127 lines (110 loc) · 3.4 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Show a warning only in interactive shells
_warn_missing() {
[[ $- == *i* ]] && printf 'Warning: %s not found; skipping %s\n' "$1" "$2" >&2
}
# Navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
# ls aliases
if command -v eza >/dev/null 2>&1; then
alias l='eza -l --icons'
alias ll='eza -la --icons'
alias la='eza -a --icons'
else
alias l='ls -l'
alias ll='ls -la'
alias la='ls -a'
fi
# Allow aliases to work with sudo
alias sudo='sudo '
alias path='echo "$PATH" | tr ":" "\n"'
# TODO: Remove when Zed copilot process duplication is fixed
# List all copilot language server instances
alias colist="ps aux | grep '[c]opilot-language-server'"
# Kill all but the most recent instance of the copilot language server
alias coclean="pgrep -f copilot-language-server | sort -n | head -n -1 | xargs -r kill"
# Kill all copilot language server processes
alias conuke="pkill -f copilot-language-server"
# Create directory and enter it
mkcd() {
mkdir -p "$1" && cd "$1"
}
# Kill process with fuzzy search
fkill() {
if ! command -v fzf >/dev/null 2>&1; then
_warn_missing fzf "fkill"
return 1
fi
local pid
pid=$(ps -ef | sed 1d |
fzf --multi \
--header="Select processes to kill" \
--preview="echo PID: {2}; echo CMD: {8..}" \
--preview-window=up:3:wrap \
--bind "change:top" |
awk '{print $2}')
if [[ -n "$pid" ]]; then
echo "Killing $pid"
echo "$pid" | xargs kill -9
else
printf 'No process selected, aborting\n' >&2
fi
}
# Publish current directory to GitHub using gh cli (supports optional --private flag)
git-publish() {
if ! command -v gh >/dev/null 2>&1; then
_warn_missing gh "git-publish"
return 1
fi
local repo_name
repo_name=$(basename "$(git rev-parse --show-toplevel)")
local visibility="--public" # Default to public
if [[ "$1" == "--private" ]]; then
visibility="--private"
echo "Creating private repository"
else
echo "Creating public repository"
fi
gh repo create "$repo_name" $visibility --source=. --remote=origin
}
# Set alias only if the command exists
_alias_if() {
# _alias_if <alias> <required_command> [alias_value...]
local name="$1"
local cmd="$2"
shift 2
# If the command exists, create the alias
if command -v "$cmd" >/dev/null 2>&1; then
alias "$name"="$*"
else
_warn_missing "$cmd" "alias for $name"
fi
}
# Replace default commands with enhanced versions
# _alias_if <alias> <required_command> [alias_value...]
_alias_if cat bat 'bat'
_alias_if man batman 'batman'
_alias_if top btop 'btop'
_alias_if ls eza 'eza --icons'
_alias_if tree eza 'eza --tree'
_alias_if find fd 'fd'
_alias_if fzfp fzf 'fzf --preview "bat --color=always --style=numbers {}"' # Start fzf with bat preview
_alias_if grep rg 'rg'
_alias_if ptop powertop 'powertop'
_alias_if ff fastfetch 'fastfetch'
_alias_if sys systemctl-tui 'systemctl-tui'
_alias_if lg lazygit 'lazygit'
_alias_if zed zeditor 'zeditor'
_alias_if zen zen-beta 'zen-beta'
# Clipboard utilities
_alias_if cwd xclip 'pwd | xclip -selection clipboard' # Copy working directory to clipboard
if command -v xclip >/dev/null 2>&1; then
cfp() {
readlink -f "$1" | xclip -selection clipboard
}
else
_warn_missing xclip "cfp alias"
fi
unset -f _warn_missing
unset -f _alias_if