-
Notifications
You must be signed in to change notification settings - Fork 1
/
aliases
147 lines (136 loc) · 3.71 KB
/
aliases
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Colorized output
alias grep='grep --color=auto'
alias diff='diff --color=auto'
# ls shortcuts
alias ls='exa'
alias l='exa'
alias ll='exa -al --git'
alias tree='exa -Tl'
# Easier directory jumping
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias cd..='cd ..'
# Systemctl shortcuts
alias start='systemctl start'
alias stop='systemctl stop'
alias restart='systemctl restart'
alias status='systemctl status'
# Frequently used commands
alias v='nvim'
alias vi='nvim'
alias vim='nvim'
alias rm='rm -Iv'
alias ipy='exec ipython'
alias hig='history 0 | grep -i'
alias todo='rg -i "todo|fixme|xxx"'
alias rg='rg -S'
alias g='git'
# Who calls ghostscript from the command line anyway?
alias gs='git status -sb #'
alias gdfs='LESS="$LESS -S" g df'
alias open='xdg-open'
alias psh='prefix-shell'
alias mywatch='watch -c -d -e -t -n 1'
alias servewd='python -m http.server'
ranger_cd() {
local temp_file dir
temp_file="$(mktemp --tmpdir "ranger_cd.XXXX")"
ranger --choosedir="$temp_file" -- "$PWD"
dir=$(cat "$temp_file")
\rm "$temp_file"
if [ "$dir" != "$PWD" ]; then
cd -- "$dir" || return
fi
}
alias r='ranger_cd'
alias tf='terraform'
c() {
if [[ $# -gt 0 ]]; then
cd "$@"
return $?
fi
dir="$(cd ~ && fd --follow --type directory | fzf)"
if [[ -n "$dir" ]]; then
cd "$HOME/$dir" || return 1
else
return 2
fi
}
psg() {
# The extra grep is just for highlighting.
# We don't pipe here because then the extra grep would be part
# of the output.
grep -i "$*" <<<"$(pgrep -fia "$*")"
}
cl() {
cd "$1" && ls -AFhlv
}
man() {
# Use nice formatting for man pages
env \
LESS_TERMCAP_mb=$'\E[5m' \
LESS_TERMCAP_md=$'\E[32m' \
LESS_TERMCAP_me=$'\E[0m' \
LESS_TERMCAP_so=$'\E[3m\E[48;5;235m' \
LESS_TERMCAP_se=$'\E[0m' \
LESS_TERMCAP_us=$'\E[3m' \
LESS_TERMCAP_ue=$'\E[0m' \
/usr/bin/man "$@"
}
clone() {
cd "$HOME/repos" || return 1
git clone "$1"
repo=$(echo "$1" | perl -pe 's|.*/(.*?)(\.git)?$|\1|')
cd "$repo" || return 1
}
pgen() {
pass generate -c "$@" 30
}
# checkout git branch (including remote branches), sorted by most recent commit, limit 30 last branches
fco() {
local branches branch
branches=$(git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format="%(refname:short)") &&
branch=$(echo "$branches" |
fzf --height $(( 2 + $(wc --lines <<< "$branches") )) --no-multi) &&
git checkout $(echo "$branch" | sed 's/.* //' | sed 's#remotes/[^/]*/##')
}
# git commit browser
flg() {
git log --graph --color=always \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
fzf --ansi --no-sort --reverse --tiebreak=index --bind=ctrl-s:toggle-sort \
--bind "ctrl-m:execute:
(grep -o '[a-f0-9]\{7\}' | head -1 |
xargs -I % sh -c 'git show --color=always % | less -R') << 'FZF-EOF'
{}
FZF-EOF"
}
# Override built-in `cd` to auto-activate Python virtualenvs
function cd() {
# Find the closest virtualenv if any along the path ancestry
function search_virtualenv() {
while [[ "$PWD" != "/" ]]; do
local possible_venv="$PWD/.venv"
if [[ -d "$possible_venv" ]]; then
echo "$possible_venv"
return 0
fi
builtin cd .. || return 1
done
}
builtin cd "$@" || return
local venv
venv=$(search_virtualenv) || return 1
if [[ "$VIRTUAL_ENV" == "$venv" ]]; then
return 0
fi
if [[ -n "$VIRTUAL_ENV" ]]; then
deactivate
fi
if [[ -n "$venv" ]]; then
source "$venv/bin/activate"
fi
}
# vim:filetype=sh