-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzsh_functions
150 lines (122 loc) · 4.04 KB
/
zsh_functions
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
148
149
150
function finder_edit() {
vim $(find $@ -type f | fzf --preview 'cat {}')
}
function finder() {
find $@ -type f | fzf --preview 'cat {}'
}
function kill_finder() {
ps -fea | fzf | awk '{print $2}' | xargs kill -9
}
function ctagReferences(){
ctags -R --exclude=.git
}
function search_history(){
local selected_command=$(fc -rl 1 | awk '{$1="";print substr($0,2)}' | sort | uniq | fzf --border --color=bg+:24)
LBUFFER=$selected_command
}
zle -N search_history
bindkey '^r' search_history
zle -N finder_edit
bindkey '^e' finder_edit
function git_fetch_all_branch() {
git branch -r | grep -v '\->' | while read remote;
do
git branch --track "${remote#uetiko/}" "$remote";
done
git fetch --all
git pull --all
}
function git_search_log(){
git log --graph --color=always --no-merges \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" | \
fzf --ansi --no-sort --reverse --tiebreak=index --preview \
'f() { set -- $(echo -- "$@" | grep -o "[a-f0-9]\{7\}"); [ $# -eq 0 ] || git show --color=always $1 ; }; f {}' \
--bind "j:down,k:up,alt-j:preview-down,alt-k:preview-up,ctrl-f:preview-page-down,ctrl-b:preview-page-up,q:abort,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" --preview-window=right:60%
}
function docker_stop_all(){
echo -e "\e[94m"
docker ps
echo -e "\e[92mCONTAINER ID\e[93m"
docker ps | awk '{print $1}' | xargs docker stop
echo -e "\e[39m"
}
function cd() {
if [[ "$#" != 0 ]]; then
builtin cd "$@";
return
fi
while true;
do
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 --color=always "${__cd_path}";
')"
[[ ${#dir} != 0 ]] || return 0
builtin cd "$dir" &> /dev/null
done
}
function docker_remove_image(){
local cid
cid=$(docker images | fzf -q "$1" | awk '{print $3}')
[ -n "$cid" ] && docker rmi -f "$cid"
}
function docker_stop() {
local cid
cid=$(docker ps | sed 1d | fzf -q "$1" | awk '{print $1}')
[ -n "$cid" ] && docker stop "$cid"
}
man_finder() {
man -k . | fzf --prompt='Man> ' | awk '{print $1}' | xargs -r man
}
function list_enviroments(){
printenv | fzf --border
}
function count_files_by_exstension() {
find $@ -type f | awk -F . '{print $NF}' | sort | uniq -c \
| awk '{print $2,$1}' | fzf
}
function preview_file_finder() {
find $@ -type f | fzf --preview="cat {-1}" --header-lines=1 --color=bg+:24 \
--bind "alt-j:preview-down,alt-k:preview-up,ctrl-f:preview-page-down,ctrl-b:preview-page-up" \
--inline-info --border --tabstop=2 --border
}
#Use only with root
function apt_finder_installer(){
apt-cache search $@ | fzf -m --ansi --reverse --inline-info \
| awk '{print $1}' | xargs -r apt-get install -y
}
function droidcam_up(){
adb start-server
droidcam-cli -v adb 4747
}
function kill_adb_server(){
adb kill-server
}
function docker_remove_volumens(){
docker volume ls -qf dangling=true | xargs -r docker volume rm
}
function git_activiy() {
git for-each-ref --sort=-committerdate refs/remotes/azure --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) %(authoremail) - (%(color:green)%(committerdate:relative)%(color:reset))' --count=20
}
function git_change_branch(){
git for-each-ref --sort='-authordate' --format='%1B[0;34m%(refname:short)%1B[m ===> %1B[1;35m%(subject)' refs/heads | sed -e 's-refs/heads/--' | fzf --ansi -m --reverse | awk '{print $1}' | xargs git checkout
}
git_add_patch_file(){
git status --untracked-files=no | fzf --reverse | awk '{print $2}' | xargs git add -p
}
git_pull_current_branch(){
git branch --show-current | xargs git pull $@
}
git_push_current_branch(){
git branch --show-current | xargs git push $@
}