-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfzfrc
182 lines (164 loc) · 5.39 KB
/
fzfrc
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# TODO
# -Add binding to pin current item to then relax the filter in order to
# explore the environment
# -Add some means to add an ordering to the selection of --multi
# -Add some means to match content in a particular column
# --bind 'change:top'
# --bind 'alt-b:deselect-all'
export FZF_DEFAULT_OPTS="
--bind 'alt-a:select-all'
--bind 'alt-d:page-down'
--bind 'alt-u:page-up'
--bind 'ctrl-r:toggle-sort'
--bind 'ctrl-q:toggle-preview'
--bind 'ctrl-alt-j:preview-page-down'
--bind 'ctrl-alt-k:preview-page-up'
--bind 'ctrl-alt-l:toggle-preview-wrap'
--bind 'ctrl-l:cancel'
--bind 'ctrl-o:toggle-all'
--bind 'alt-c:toggle-all'
--bind 'ctrl-n:next-history'
--bind 'ctrl-p:previous-history'
--bind 'ctrl-t:execute(tmux set-buffer {})'
--bind 'ctrl-x:execute(xclip -selection clipboard -in <<< {})'
--bind 'ctrl-v:execute(tmux split -v nvim +set\ bt=nofile +let\ @\\\"=\\\"{+}\\\" +normal\ pgg0)' \
--bind 'tab:toggle-up'
--bind 'btab:toggle-down'
--ansi
--inline-info
--history=${HOME}/.fzf_history
--exact
--prompt=\": \"
"
export FZF_TMUX=1
export FZF_TMUX_HEIGHT=90%
# TODO: add binding for vared
ee() {
typeset | fzf --multi | cut -d= -f1
}
fbr() {
local refs_filter=${*}
local object
object=$(git -c color.ui=always for-each-ref \
${refs_filter} \
--format="%(HEAD)%(color:red)%(objectname:short)%(color:reset) %09 (%(color:green)%(committerdate:local) - %(committerdate:relative)%(color:reset)) %09 %(color:yellow)%(refname:short)%(color:reset) %(contents:subject) (%(color:green)%(authorname)%(color:reset))" \
--sort=-committerdate |
fzf-tmux --tabstop=14 --ansi --no-sort | cut -f 1 | tr -d \*)
echo sha1 = $object
git checkout $=object
}
fbT() {
fbr "refs/tags"
}
fbS() {
fbr "refs/stash"
}
fbR() {
fbr "refs/heads"
}
# fshow - git commit browser
fshow() {
git log --all --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"
}
# fs - tmux session management
fs() {
local session
session=$(tmux list-sessions -F "#{session_name}" | \
fzf --query="$1" --select-1 --exit-0) &&
tmux switch-client -t "$session"
}
ftpane() {
# TODO:
# -check if already running
# -focus self
# -what about colors
panes=$( \
tmux list-panes -aF '#{window_activity_flag} #{window_bell_flag} #{window_silence_flag} #{window_stack_index} #{wrap_flag} #{window_flags}\t#{t:window_activity}\t[#{session_name}]\t#{window_index}|#{=13:window_name}\t#{s,/dev/,,:pane_tty}\t#{pane_id}\t#{pane_pid}\t#{pane_index}|#{=13:pane_current_command}\t#{pane_current_path}:#{pane_title}' |
sort -k 7dr |
grep -v $$ # TODO: add \t-regex
)
target=$(echo "$panes" | fzf +m --header=A\ B\ S\ I\ W\ F\ $'\t'\[ACTIVITY\]$'\t\t'\[SESSION\]$'\t'\ \|WINDOW$'\t'TTY$'\t'P_ID$'\t'P_PID$'\t'\ \|PANE$'\t'CWD:TITLE --tabstop=14 --layout=reverse ) || return
tmux switch-client -t $(echo $target | cut -f 6)
}
# gch - browse chrome history
gch() {
local title_width sep tmp_file
title_width=$(( COLUMNS / 2 ))
sep='{{::}}'
tmp_file=$(mktemp)
cp -f "$HOME/.config/google-chrome/Default/History" $tmp_file &&
sqlite3 -separator $sep $tmp_file \
"select datetime((last_visit_time/1000000)-11644473600, 'unixepoch', 'localtime'), visit_count, substr(title, 1, $title_width), url from urls order by last_visit_time desc" |
awk -F $sep '{printf "%s #%s %-'$title_width's \x1b[36m%s\n", $1, $2, $3, $4}' |
fzf --ansi --multi \
--prompt "chrome history ($(jq -c '.["account_info"] | .[0] | .email' "$(dirname "$(readlink ~/.config/google-chrome-history)")"/Preferences)): " |
sed 's#.*\(https*://\)#\1#' | xargs xdg-open > /dev/null 2>&1
zle && zle redisplay
}
zle -N gch; bindkey '\eU' gch
# gcb - browse chrome bookmarks
gcb() {
setopt pipefail
local urls
urls=$(chrome-bookmarks.rb |
sort -r |
fzf \
--ansi \
--bind 'ctrl-x:execute(cut -f 3 <<< {} | xclip -selection clipboard -in)' \
--prompt "chrome bookmarks ($(jq -c '.["account_info"] | .[0] | .email' ~/.config/google-chrome/Default/Preferences)): " \
--multi |
cut -f 3) &&
xdg-open $=urls
}
zle -N gcb;
bindkey '\eB' gcb
bindkey '\eI' gcb
# twf - browse twitter favorites
twf() {
setopt pipefail
local tweed_ids
# sed -n '/^[[:digit:]]\{15,\}/{x;p;d};H;x;s/\r\n/ /g;x'
tweed_ids=$(t favorites --long --number 1000 |
fzf \
--ansi \
--prompt "twitter favs: " \
--multi |
sed -nE 's,([0-9]* ).*,https://twitter.com/statuses/\1,p' ) &&
exo-open $=tweed_ids
}
zle -N twf; bindkey '\eT' twf
__fzfz() {
unset REPORTTIME
eval "z -l|cut -f 2" | fzf --prompt='z (dirs): ' --tac --tiebreak=index -m --preview="ls --color=always -al {} " |
while read item; do
printf '%q ' "$item"
done
echo
}
fzfz_file_widget() {
LBUFFER="${LBUFFER}$(__fzfz)"
zle redisplay
}
zle -N fzfz_file_widget
bindkey '^G' fzfz_file_widget
fzf_locate_widget() {
BUFFER="$LBUFFER$(
command locate \* |
fzf --multi --prompt='locate: ' --preview="file {}" |
while read file; do
qfile="${(q)file} "
CURSOR+=$#qfile # FIXME: cursor does not advance
echo -n $qfile
done
)$RBUFFER"
zle redisplay
}
zle -N fzf_locate_widget; bindkey '^x^l' fzf_locate_widget
# vim:ft=sh