mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-18 08:13:40 -05:00
added fco_preview: might be really bad code, but it "works for me!"
27
Examples.md
27
Examples.md
@@ -244,7 +244,7 @@ Replacing `eval` with `print -z` will push the arguments onto the editing buffer
|
|||||||
|
|
||||||
#### With write to terminal capabilities
|
#### With write to terminal capabilities
|
||||||
|
|
||||||
These have been tested in bash.
|
These have been tested in bash.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# fh - repeat history
|
# fh - repeat history
|
||||||
@@ -385,6 +385,24 @@ fco() {
|
|||||||
fzf-tmux -l30 -- --no-hscroll --ansi +m -d "\t" -n 2) || return
|
fzf-tmux -l30 -- --no-hscroll --ansi +m -d "\t" -n 2) || return
|
||||||
git checkout $(echo "$target" | awk '{print $2}')
|
git checkout $(echo "$target" | awk '{print $2}')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# fco_preview - checkout git branch/tag, with a preview showing the commits between the tag/branch and HEAD
|
||||||
|
fco_preview() {
|
||||||
|
local tags branches target
|
||||||
|
tags=$(
|
||||||
|
git tag | awk '{print "\x1b[31;1mtag\x1b[m\t" $1}') || return
|
||||||
|
branches=$(
|
||||||
|
git branch --all | grep -v HEAD |
|
||||||
|
sed "s/.* //" | sed "s#remotes/[^/]*/##" |
|
||||||
|
sort -u | awk '{print "\x1b[34;1mbranch\x1b[m\t" $1}') || return
|
||||||
|
target=$(
|
||||||
|
(echo "$tags"; echo "$branches") |
|
||||||
|
fzf --no-hscroll --no-multi --delimiter="\t" -n 2 \
|
||||||
|
--preview="git log -200 --pretty=format:%s $(echo {+2..} | sed 's/$/../' )" ) || return
|
||||||
|
git checkout $(echo "$target" | awk '{print $2}')
|
||||||
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -481,7 +499,7 @@ ftags() {
|
|||||||
|
|
||||||
tm() {
|
tm() {
|
||||||
[[ -n "$TMUX" ]] && change="switch-client" || change="attach-session"
|
[[ -n "$TMUX" ]] && change="switch-client" || change="attach-session"
|
||||||
if [ $1 ]; then
|
if [ $1 ]; then
|
||||||
tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return
|
tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return
|
||||||
fi
|
fi
|
||||||
session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) && tmux $change -t "$session" || echo "No sessions found."
|
session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) && tmux $change -t "$session" || echo "No sessions found."
|
||||||
@@ -887,7 +905,7 @@ _fzf_marker_main_widget() {
|
|||||||
_fzf_marker_placeholder
|
_fzf_marker_placeholder
|
||||||
else
|
else
|
||||||
local selected
|
local selected
|
||||||
if selected=$(cat ${FZF_MARKER_CONF_DIR:-~/.config/marker}/*.txt |
|
if selected=$(cat ${FZF_MARKER_CONF_DIR:-~/.config/marker}/*.txt |
|
||||||
sed -e "s/\(^[a-zA-Z0-9_-]\+\)\s/${FZF_MARKER_COMMAND_COLOR:-\x1b[38;5;255m}\1\x1b[0m /" \
|
sed -e "s/\(^[a-zA-Z0-9_-]\+\)\s/${FZF_MARKER_COMMAND_COLOR:-\x1b[38;5;255m}\1\x1b[0m /" \
|
||||||
-e "s/\s*\(#\+\)\(.*\)/${FZF_MARKER_COMMENT_COLOR:-\x1b[38;5;8m} \1\2\x1b[0m/" |
|
-e "s/\s*\(#\+\)\(.*\)/${FZF_MARKER_COMMENT_COLOR:-\x1b[38;5;8m} \1\2\x1b[0m/" |
|
||||||
fzf --bind 'tab:down,btab:up' --height=80% --ansi -q "$LBUFFER"); then
|
fzf --bind 'tab:down,btab:up' --height=80% --ansi -q "$LBUFFER"); then
|
||||||
@@ -903,7 +921,7 @@ _fzf_marker_placeholder() {
|
|||||||
strp=$(echo "$strp" | head -1)
|
strp=$(echo "$strp" | head -1)
|
||||||
pos=$(echo $strp | cut -d ":" -f1)
|
pos=$(echo $strp | cut -d ":" -f1)
|
||||||
placeholder=$(echo $strp | cut -d ":" -f2)
|
placeholder=$(echo $strp | cut -d ":" -f2)
|
||||||
if [[ -n "$1" ]]; then
|
if [[ -n "$1" ]]; then
|
||||||
BUFFER=$(echo $BUFFER | sed -e "s/{{//" -e "s/}}//")
|
BUFFER=$(echo $BUFFER | sed -e "s/{{//" -e "s/}}//")
|
||||||
CURSOR=$(($pos + ${#placeholder} - 4))
|
CURSOR=$(($pos + ${#placeholder} - 4))
|
||||||
else
|
else
|
||||||
@@ -919,4 +937,3 @@ zle -N _fzf_marker_placeholder_widget
|
|||||||
bindkey "${FZF_MARKER_MAIN_KEY:-\C-@}" _fzf_marker_main_widget
|
bindkey "${FZF_MARKER_MAIN_KEY:-\C-@}" _fzf_marker_main_widget
|
||||||
bindkey "${FZF_MARKER_PLACEHOLDER_KEY:-\C-v}" _fzf_marker_placeholder_widget
|
bindkey "${FZF_MARKER_PLACEHOLDER_KEY:-\C-v}" _fzf_marker_placeholder_widget
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user