-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaliases
More file actions
108 lines (92 loc) · 2.73 KB
/
aliases
File metadata and controls
108 lines (92 loc) · 2.73 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
#########################################################
# Shell aliases
# Shortcuts
alias rials="rails"
alias g="git status"
alias gg="git diff"
alias gdc="git diff --cached"
alias gb="gbr"
alias c="./bin/rails console"
alias r="./bin/rspec"
alias ws="ruby -run -e httpd . -p8000"
alias rg3="rg --context 3"
alias :q="exit"
alias dc="docker-compose"
alias history="history 1" # all history since forever
alias python='python3'
alias python2='python3'
alias vsc='code-insiders .'
alias pr='gh pr checkout'
alias prc='gh pr create --web'
alias chx='gh pr checks'
alias n='nvim'
alias j='zi'
alias z='zellij --layout ~/.config/zellij/dev.kdl'
alias zd='zellij --config ~/.config/zellij/config-dark.kdl --layout ~/.config/zellij/dev.kdl'
# Include custom aliases
[[ -f ~/.aliases.local ]] && source ~/.aliases.local
#########################################################
# FZF
is_in_git_repo() {
git rev-parse HEAD > /dev/null 2>&1
}
fzf-down() {
fzf --height 80% --min-height 20 --border --bind ctrl-/:toggle-preview "$@"
}
# checkout local git branches
function gbr() {
is_in_git_repo || return
local branches branch
branches=$(git for-each-ref --count=15 --sort=-committerdate refs/heads/ --format="%(refname:short)") &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
# git checkout (with remote branches)
function gco() {
git fetch origin --prune
local branches branch
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
function gs() {
is_in_git_repo || return
git -c color.status=always status --short |
fzf-down -m --ansi --nth 2..,.. \
--preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1})' |
cut -c4- | sed 's/.* -> //'
}
# kill process
function fkill() {
local pid
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
if [ "x$pid" != "x" ]
then
echo $pid | xargs kill -${1:-9}
fi
}
function cd() {
if [[ "$#" != 0 ]]; then
builtin cd "$@";
return
fi
local lsd=$(echo ".." && ls -p | grep '/$' | sed 's;/$;;')
local dir="$(printf '%s\n' "${lsd[@]}" |
fzf --reverse --preview '
__cd_nxt="$(echo {})";
__cd_path="$(echo $(pwd)/${__cd_nxt} | sed "s;//;/;")";
echo $__cd_path;
echo;
ls -p -G "${__cd_path}";
')"
[[ ${#dir} != 0 ]] || return 0
builtin cd "$dir" &> /dev/null
}
#########################################################
# OSX
# Open file in QuickLook
function ql () {
qlmanage -p "$*" >& /dev/null;
}