aboutsummaryrefslogtreecommitdiffstats
path: root/bashrc
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2023-06-07 17:27:21 +0100
committerMatthew Lemon <y@yulqen.org>2023-06-07 17:27:21 +0100
commit7dbed9d3204175743f1da1fefdeb564b94d1aac5 (patch)
tree6239b437c5b4754c9532a0aabdd39816223df9e7 /bashrc
parent9206ded0e7b0c3faa79e7fad1a9b7de0907f87fc (diff)
Adds some fzf functions
Diffstat (limited to 'bashrc')
-rw-r--r--bashrc111
1 files changed, 108 insertions, 3 deletions
diff --git a/bashrc b/bashrc
index 4bd483d..5d19ec1 100644
--- a/bashrc
+++ b/bashrc
@@ -37,6 +37,7 @@ alias pacdel="pacman -Qq | fzf --multi --preview 'pacman -Qi {1}' | xargs -ro su
alias gloga='git log --oneline --decorate --graph --all'
alias batnote='batnote-source-code'
alias am='append_to_masterlist'
+alias vi='vim'
alias ls='ls --color=auto'
alias h='hey_openai'
alias hd='openai_data'
@@ -80,9 +81,113 @@ export=GPG_TTY="$(tty)"
export=SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
gpgconf --launch gpg-agent
-#completion for todo.sh
-source ~/Documents/Notes/todo/todo_completion
-complete -o default -o nospace -F _todo t
+bind '"\C-r": "\C-x1\e^\er"'
+bind -x '"\C-x1": __fzf_history';
+
+__fzf_history ()
+{
+__ehc $(history | fzf --tac --tiebreak=index | perl -ne 'm/^\s*([0-9]+)/ and print "!$1"')
+}
+
+__ehc()
+{
+if
+ [[ -n $1 ]]
+then
+ bind '"\er": redraw-current-line'
+ bind '"\e^": magic-space'
+ READLINE_LINE=${READLINE_LINE:+${READLINE_LINE:0:READLINE_POINT}}${1}${READLINE_LINE:+${READLINE_LINE:READLINE_POINT}}
+ READLINE_POINT=$(( READLINE_POINT + ${#1} ))
+else
+ bind '"\er":'
+ bind '"\e^":'
+fi
+}
+
+# fkill - kill processes - list only the ones you can kill. Modified the earlier script.
+fkill() {
+ local pid
+ if [ "$UID" != "0" ]; then
+ pid=$(ps -f -u $UID | sed 1d | fzf -m | awk '{print $2}')
+ else
+ pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
+ fi
+
+ if [ "x$pid" != "x" ]
+ then
+ echo $pid | xargs kill -${1:-9}
+ fi
+}
+
+# fco_preview - checkout git branch/tag, with a preview showing the commits between the tag/branch and HEAD
+fco_preview() {
+ local tags branches target
+ branches=$(
+ git --no-pager branch --all \
+ --format="%(if)%(HEAD)%(then)%(else)%(if:equals=HEAD)%(refname:strip=3)%(then)%(else)%1B[0;34;1mbranch%09%1B[m%(refname:short)%(end)%(end)" \
+ | sed '/^$/d') || return
+ tags=$(
+ git --no-pager tag | awk '{print "\x1b[35;1mtag\x1b[m\t" $1}') || return
+ target=$(
+ (echo "$branches"; echo "$tags") |
+ fzf --no-hscroll --no-multi -n 2 \
+ --ansi --preview="git --no-pager log -150 --pretty=format:%s '..{2}'") || return
+ git checkout $(awk '{print $2}' <<<"$target" )
+}
+
+# fshow - git commit browser
+fshow() {
+ 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"
+}
+
+# ftags - search ctags
+ftags() {
+ local line
+ [ -e tags ] &&
+ line=$(
+ awk 'BEGIN { FS="\t" } !/^!/ {print toupper($4)"\t"$1"\t"$2"\t"$3}' tags |
+ cut -c1-80 | fzf --nth=1,2
+ ) && ${EDITOR:-vim} $(cut -f3 <<< "$line") -c "set nocst" \
+ -c "silent tag $(cut -f2 <<< "$line")"
+}
+
+# tm - create new tmux session, or switch to existing one. Works from within tmux too. (@bag-man)
+# `tm` will allow you to select your tmux session via fzf.
+# `tm irc` will attach to the irc session (if it exists), else it will create it.
+
+tm() {
+ [[ -n "$TMUX" ]] && change="switch-client" || change="attach-session"
+ if [ $1 ]; then
+ tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return
+ fi
+ session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) && tmux $change -t "$session" || echo "No sessions found."
+}
+
+tmuxkillf() {
+ local sessions
+ sessions="$(tmux ls | fzf --exit-0 --multi)" || return $?
+ local i
+ for i in "${sessions[@]}"
+ do
+ if [[ $i =~ ([^:]*):.* ]]; then
+ echo "Killing ${BASH_REMATCH[1]}"
+ tmux kill-session -t "${BASH_REMATCH[1]}"
+ fi
+ done
+}
+
+fman() {
+ man -k . | fzf -q "$1" --prompt='man> ' --preview $'echo {} | tr -d \'()\' | awk \'{printf "%s ", $2} {print $1}\' | xargs -r man | col -bx | bat -l man -p --color always' | tr -d '()' | awk '{printf "%s ", $2} {print $1}' | xargs -r man
+}
+# Get the colors in the opened man page itself
+export MANPAGER="sh -c 'col -bx | bat -l man -p --paging always'"
source $HOME/secrets