-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zsh_aliases
95 lines (85 loc) · 2.47 KB
/
.zsh_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
DEFAULT_ORG='timmysilv'
SRC_ROOT="$HOME/src/github.com"
# general aliases
alias k='kubectl'
alias c='clear'
alias s='screen'
alias fg='fg &>/dev/null'
alias py='python3'
alias mk='make -j 4'
alias hs='c && cat ~/.screenhelp'
alias lsd='ls -hAlt --color=auto'
alias drm='docker rm `docker ps -a -f status=exited -q`'
alias drmi='docker rmi `docker images -f dangling=true -q`'
alias ports='sudo lsof -i -P | grep LISTEN | grep -E ":\d+"'
alias cprof='curl -s -o /dev/null -w "time_namelookup: %{time_namelookup}s\n time_connect: %{time_connect}s\n time_appconnect: %{time_appconnect}s\n time_pretransfer: %{time_pretransfer}s\n time_redirect: %{time_redirect}s\n time_starttransfer: %{time_starttransfer}s\n ----------\n time_total: %{time_total}s\n"'
# git
alias g='git'
alias ga='g add .'
alias gb='g branch'
alias gp='g push'
alias gs='g status'
alias gl='g log --oneline -n 30'
alias gd='g diff'
alias gcm='g commit -m'
alias gpu='g pull'
alias grb='g rebase -i `git_main_branch`'
alias gdv='g difftool --tool=vimdiff --no-prompt'
alias gdf='g diff `git_main_branch` --name-status'
alias gco='g checkout'
alias gch='g checkout `git_main_branch`'
alias gcd='cd $(g rev-parse --show-toplevel)'
# vim and files
alias v='vim'
alias vrc='v ~/.vimrc'
alias vz='v -p ~/.zsh_aliases ~/.zshrc'
alias sz='source ~/.zshrc'
# functions
# split a variable on the ':' delimiter
function pp() {
tr ':' '\n' <<< $(printenv $1)
}
# convert string to list, save in $ret
function str_to_list() {
ret=($(echo "$1" | tr '\n' ' '))
}
# clone and organize repos, specify ORG as env-var if not the default
function gclone() {
ORG=${ORG:-$DEFAULT_ORG}
DIR=$SRC_ROOT/$ORG
mkdir -p $DIR
cd $DIR
git clone [email protected]:$ORG/$1.git
cd $1
unset ORG
}
function scd() {
repo=$2
org=$DEFAULT_ORG
if [[ $repo == "" ]]; then
repo=$1
else
org=$1
fi
cd $SRC_ROOT/$org/$repo
}
function _scd_complete() {
org=$DEFAULT_ORG
if [[ $COMP_CWORD -eq 2 ]]; then
org=${COMP_WORDS[1]}
elif [[ $COMP_CWORD -gt 2 ]]; then
return
fi
local ls_result=$(ls -p ${SRC_ROOT}/${org} | grep /$)
local latest=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=()
for i in $ls_result; do
if [[ $i == ${latest}* ]]; then
COMPREPLY+=($i)
fi
done
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
COMPREPLY=($ls_result)
fi
}
complete -F _scd_complete scd