Migrate to chezmoi
Move config files from config to chezmoi Add script to auto install packages with DNF and Cargo
This commit is contained in:
parent
110e0882c6
commit
224c7ed45c
1654 changed files with 470035 additions and 51 deletions
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select clipboard history. Press TAB to mark multiple items.'"
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
if ! [ -x "$(command -v copyq)" ]; then
|
||||
action="buffer"
|
||||
elif [ -z "$1" ]; then
|
||||
action="system"
|
||||
else
|
||||
action="$1"
|
||||
fi
|
||||
|
||||
if [[ "$action" == "system" ]]; then
|
||||
item_numbers=$(copyq count)
|
||||
contents="[cancel]\n"
|
||||
index=0
|
||||
while [ "$index" -lt "$item_numbers" ]; do
|
||||
_content="$(copyq read ${index} | tr '\n' ' ' | tr '\\n' ' ')"
|
||||
contents="${contents}copy${index}: ${_content}\n"
|
||||
index=$((index + 1))
|
||||
done
|
||||
copyq_index=$(printf "$contents" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS --preview=\"echo {} | sed -e 's/^copy//' -e 's/: .*//' | xargs -I{} copyq read {}\"" | sed -e 's/^copy//' -e 's/: .*//')
|
||||
[[ "$copyq_index" == "[cancel]" || -z "$copyq_index" ]] && exit
|
||||
echo "$copyq_index" | xargs -I{} sh -c 'tmux set-buffer -b _temp_tmux_fzf "$(copyq read {})" && tmux paste-buffer -b _temp_tmux_fzf && tmux delete-buffer -b _temp_tmux_fzf'
|
||||
elif [[ "$action" == "buffer" ]]; then
|
||||
selected_buffer=$(tmux list-buffers | sed -e 's/:.*bytes//' -e '1s/^/[cancel]\n/' -e 's/: "/: /' -e 's/"$//' | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS --preview=\"echo {} | sed -e 's/\[cancel\]//' -e 's/:.*$//' | head -1 | xargs tmux show-buffer -b\"" | sed 's/:.*$//')
|
||||
[[ "$selected_buffer" == "[cancel]" || -z "$selected_buffer" ]] && exit
|
||||
echo "$selected_buffer" | xargs -I{} sh -c 'tmux paste-buffer -b {}'
|
||||
fi
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select a command.'"
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
target_origin=$(tmux list-commands)
|
||||
target=$(printf "[cancel]\n%s" "$target_origin" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS" | grep -o '^[^[:blank:]]*')
|
||||
|
||||
[[ "$target" == "[cancel]" || -z "$target" ]] && exit
|
||||
tmux command-prompt -I "$target"
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
copy_mode_commands="append-selection Append the selected buffer to the clipboard
|
||||
append-selection-and-cancel Append the selected buffer to the clipboard and cancel the current command
|
||||
back-to-indentation Move the cursor back to the indentation
|
||||
begin-selection Begin selection in the buffer
|
||||
bottom-line Move to the bottom line of the buffer
|
||||
cancel Cancel the current command
|
||||
clear-selection Clear the current selection in the buffer
|
||||
copy-end-of-line [<prefix>] Copy from the cursor position to the end of the line. If no prefix is given, it copies to the clipboard
|
||||
copy-end-of-line-and-cancel [<prefix>] Copy from the cursor position to the end of the line and cancel the current command
|
||||
copy-pipe-end-of-line [<command>] [<prefix>] This is equivalent to the copy-end-of-line method, but allows running a shell command on the text, and then copies it to the clipboard
|
||||
copy-line [<prefix>] Copy the entire line irrespective of the cursor position. If no prefix is given, it copies to the clipboard
|
||||
copy-line-and-cancel [<prefix>] Copy the entire line and cancel the current command
|
||||
copy-selection [<prefix>] This is equivalent to the window_copy_copy_selection method. It simply copies the selected text to the clipboard without any additional processing
|
||||
copy-selection-and-cancel [<prefix>] Copy the current selection and cancel the current command
|
||||
cursor-down Move the cursor down
|
||||
cursor-left Move the cursor left
|
||||
cursor-right Move the cursor right
|
||||
cursor-up Move the cursor up
|
||||
end-of-line Move the cursor to the end of the line
|
||||
goto-line <line> Go to the specific line
|
||||
history-bottom Scroll to the bottom of the history
|
||||
history-top Scroll to the top of the history
|
||||
jump-again Repeat the last jump
|
||||
jump-backward <to> Jump backwards to the specified text
|
||||
jump-forward <to> Jump forward to the specified text
|
||||
jump-to-mark Jump to the last mark
|
||||
middle-line Move to the middle line of the buffer
|
||||
next-matching-bracket Move to the next matching bracket
|
||||
next-paragraph Move to the next paragraph
|
||||
next-word Move to the next word
|
||||
page-down Scroll down by one page
|
||||
page-up Scroll up by one page
|
||||
previous-matching-bracket Move to the previous matching bracket
|
||||
previous-paragraph Move to the previous paragraph
|
||||
previous-word Move to the previous word
|
||||
rectangle-toggle Toggle rectangle selection mode
|
||||
refresh-from-pane Refresh the screen based on the current pane
|
||||
search-again Repeat the last search
|
||||
search-backward <for> Search backwards for the specified text
|
||||
search-forward <for> Search forward for the specified text
|
||||
select-line Select the current line
|
||||
select-word Select the current word
|
||||
start-of-line Move the cursor to the start of the line
|
||||
top-line Move to the top line of the buffer"
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select a copy-mode command.'"
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
target=$(printf "[cancel]\n%s" "$copy_mode_commands" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS" | grep -o '^[^[:blank:]]*')
|
||||
|
||||
[[ "$target" == "[cancel]" || -z "$target" ]] && exit
|
||||
tmux send-keys -X "$target"
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
compare_float() {
|
||||
if [ ${1%.*} -eq ${2%.*} ] && [ ${1#*.} \> ${2#*.} ] || [ ${1%.*} -gt ${2%.*} ]; then
|
||||
echo ">"
|
||||
else
|
||||
echo "<="
|
||||
fi
|
||||
}
|
||||
|
||||
# $TMUX_FZF_PREVIEW_OPTIONS
|
||||
fzf_version=$(fzf --version)
|
||||
fzf_version_1=$(echo "$fzf_version" | grep -o '^[[:digit:]]*\.[[:digit:]]*')
|
||||
fzf_version_2=$(echo "$fzf_version" | grep -o '^[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*' | sed 's/[[:digit:]]*\.//')
|
||||
if [ $(compare_float $fzf_version_1 "0.24") == ">" ] ||
|
||||
[ $fzf_version_1 == "0.24" ] &&
|
||||
[ $(compare_float $fzf_version_2 "24.3") == ">" ]; then
|
||||
fzf_preview_window_follow=":follow" # :follow option is only available in fzf >= 0.24.4
|
||||
fi
|
||||
TMUX_FZF_PREVIEW="${TMUX_FZF_PREVIEW:-1}"
|
||||
if [ "$TMUX_FZF_PREVIEW" == 1 ]; then
|
||||
TMUX_FZF_PREVIEW_OPTIONS="--preview='$current_dir/.preview {}' --preview-window=$fzf_preview_window_follow"
|
||||
else
|
||||
TMUX_FZF_PREVIEW_OPTIONS="--preview='$current_dir/.preview {}' --preview-window=${fzf_preview_window_follow}:hidden"
|
||||
fi
|
||||
|
||||
# $TMUX_FZF_BIN
|
||||
TMUX_FZF_BIN="$current_dir/.fzf-tmux"
|
||||
|
||||
# $TMUX_FZF_OPTIONS
|
||||
tmux_version=$(tmux -V | grep -oE '[0-9]+\.[0-9]*')
|
||||
if [ $(compare_float $tmux_version "3.1") == ">" ]; then
|
||||
[ -z "$TMUX_FZF_OPTIONS" ] && TMUX_FZF_OPTIONS="-p -w 62% -h 38% -m"
|
||||
else
|
||||
[ -z "$TMUX_FZF_OPTIONS" ] && TMUX_FZF_OPTIONS="-m"
|
||||
fi
|
||||
|
||||
# Unset temporary variables and functions.
|
||||
unset \
|
||||
current_dir \
|
||||
compare_float \
|
||||
fzf_version \
|
||||
fzf_version_1 \
|
||||
fzf_version_2 \
|
||||
fzf_preview_window_follow \
|
||||
tmux_version
|
||||
|
|
@ -0,0 +1,229 @@
|
|||
#!/usr/bin/env bash
|
||||
# fzf-tmux: starts fzf in a tmux pane
|
||||
# usage: fzf-tmux [LAYOUT OPTIONS] [--] [FZF OPTIONS]
|
||||
|
||||
fail() {
|
||||
>&2 echo "$1"
|
||||
exit 2
|
||||
}
|
||||
|
||||
fzf="$(command -v fzf 2> /dev/null)" || fzf="$(dirname "$0")/fzf"
|
||||
[[ -x "$fzf" ]] || fail 'fzf executable not found'
|
||||
|
||||
args=()
|
||||
opt=""
|
||||
skip=""
|
||||
swap=""
|
||||
close=""
|
||||
term=""
|
||||
[[ -n "$LINES" ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}")
|
||||
[[ -n "$COLUMNS" ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}")
|
||||
|
||||
help() {
|
||||
>&2 echo 'usage: fzf-tmux [LAYOUT OPTIONS] [--] [FZF OPTIONS]
|
||||
|
||||
LAYOUT OPTIONS:
|
||||
(default layout: -d 50%)
|
||||
|
||||
Popup window (requires tmux 3.2 or above):
|
||||
-p [WIDTH[%][,HEIGHT[%]]] (default: 50%)
|
||||
-w WIDTH[%]
|
||||
-h HEIGHT[%]
|
||||
-x COL
|
||||
-y ROW
|
||||
|
||||
Split pane:
|
||||
-u [HEIGHT[%]] Split above (up)
|
||||
-d [HEIGHT[%]] Split below (down)
|
||||
-l [WIDTH[%]] Split left
|
||||
-r [WIDTH[%]] Split right
|
||||
'
|
||||
exit
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
arg="$1"
|
||||
shift
|
||||
[[ -z "$skip" ]] && case "$arg" in
|
||||
-)
|
||||
term=1
|
||||
;;
|
||||
--help)
|
||||
help
|
||||
;;
|
||||
--version)
|
||||
echo "fzf-tmux (with fzf $("$fzf" --version))"
|
||||
exit
|
||||
;;
|
||||
-p*|-w*|-h*|-x*|-y*|-d*|-u*|-r*|-l*)
|
||||
if [[ "$arg" =~ ^-[pwhxy] ]]; then
|
||||
[[ "$opt" =~ "-E" ]] || opt="-E"
|
||||
elif [[ "$arg" =~ ^.[lr] ]]; then
|
||||
opt="-h"
|
||||
if [[ "$arg" =~ ^.l ]]; then
|
||||
opt="$opt -d"
|
||||
swap="; swap-pane -D ; select-pane -L"
|
||||
close="; tmux swap-pane -D"
|
||||
fi
|
||||
else
|
||||
opt=""
|
||||
if [[ "$arg" =~ ^.u ]]; then
|
||||
opt="$opt -d"
|
||||
swap="; swap-pane -D ; select-pane -U"
|
||||
close="; tmux swap-pane -D"
|
||||
fi
|
||||
fi
|
||||
if [[ ${#arg} -gt 2 ]]; then
|
||||
size="${arg:2}"
|
||||
else
|
||||
if [[ "$1" =~ ^[0-9%,]+$ ]] || [[ "$1" =~ ^[A-Z]$ ]]; then
|
||||
size="$1"
|
||||
shift
|
||||
else
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$arg" =~ ^-p ]]; then
|
||||
if [[ -n "$size" ]]; then
|
||||
w=${size%%,*}
|
||||
h=${size##*,}
|
||||
opt="$opt -w$w -h$h"
|
||||
fi
|
||||
elif [[ "$arg" =~ ^-[whxy] ]]; then
|
||||
opt="$opt ${arg:0:2}$size"
|
||||
elif [[ "$size" =~ %$ ]]; then
|
||||
size=${size:0:((${#size}-1))}
|
||||
if [[ -n "$swap" ]]; then
|
||||
opt="$opt -p $(( 100 - size ))"
|
||||
else
|
||||
opt="$opt -p $size"
|
||||
fi
|
||||
else
|
||||
if [[ -n "$swap" ]]; then
|
||||
if [[ "$arg" =~ ^.l ]]; then
|
||||
max=$columns
|
||||
else
|
||||
max=$lines
|
||||
fi
|
||||
size=$(( max - size ))
|
||||
[[ $size -lt 0 ]] && size=0
|
||||
opt="$opt -l $size"
|
||||
else
|
||||
opt="$opt -l $size"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
--)
|
||||
# "--" can be used to separate fzf-tmux options from fzf options to
|
||||
# avoid conflicts
|
||||
skip=1
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
args+=("$arg")
|
||||
;;
|
||||
esac
|
||||
[[ -n "$skip" ]] && args+=("$arg")
|
||||
done
|
||||
|
||||
if [[ -z "$TMUX" ]]; then
|
||||
"$fzf" "${args[@]}"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# --height option is not allowed. CTRL-Z is also disabled.
|
||||
args=("${args[@]}" "--no-height" "--bind=ctrl-z:ignore")
|
||||
|
||||
# Handle zoomed tmux pane without popup options by moving it to a temp window
|
||||
if [[ ! "$opt" =~ "-E" ]] && tmux list-panes -F '#F' | grep -q Z; then
|
||||
zoomed_without_popup=1
|
||||
original_window=$(tmux display-message -p "#{window_id}")
|
||||
tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - '\\;' do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'")
|
||||
tmux swap-pane -t $tmp_window \; select-window -t $tmp_window
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
# Clean up named pipes on exit
|
||||
id=$RANDOM
|
||||
argsf="${TMPDIR:-/tmp}/fzf-args-$id"
|
||||
fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id"
|
||||
fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"
|
||||
fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
|
||||
tmux_win_opts=( $(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/') )
|
||||
cleanup() {
|
||||
\rm -f $argsf $fifo1 $fifo2 $fifo3
|
||||
|
||||
# Restore tmux window options
|
||||
if [[ "${#tmux_win_opts[@]}" -gt 0 ]]; then
|
||||
eval "tmux ${tmux_win_opts[*]}"
|
||||
fi
|
||||
|
||||
# Remove temp window if we were zoomed without popup options
|
||||
if [[ -n "$zoomed_without_popup" ]]; then
|
||||
tmux display-message -p "#{window_id}" > /dev/null
|
||||
tmux swap-pane -t $original_window \; \
|
||||
select-window -t $original_window \; \
|
||||
kill-window -t $tmp_window \; \
|
||||
resize-pane -Z
|
||||
fi
|
||||
|
||||
if [[ $# -gt 0 ]]; then
|
||||
trap - EXIT
|
||||
exit 130
|
||||
fi
|
||||
}
|
||||
trap 'cleanup 1' SIGUSR1
|
||||
trap 'cleanup' EXIT
|
||||
|
||||
envs="export TERM=$TERM "
|
||||
if [[ "$opt" =~ "-E" ]]; then
|
||||
FZF_DEFAULT_OPTS="--margin 0,1 $FZF_DEFAULT_OPTS"
|
||||
tmux_verson=$(tmux -V)
|
||||
if [[ ! $tmux_verson =~ 3\.2 ]]; then
|
||||
FZF_DEFAULT_OPTS="--border $FZF_DEFAULT_OPTS"
|
||||
opt="-B $opt"
|
||||
fi
|
||||
fi
|
||||
[[ -n "$FZF_DEFAULT_OPTS" ]] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"
|
||||
[[ -n "$FZF_DEFAULT_COMMAND" ]] && envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"
|
||||
echo "$envs;" > "$argsf"
|
||||
|
||||
# Build arguments to fzf
|
||||
opts=$(printf "%q " "${args[@]}")
|
||||
|
||||
pppid=$$
|
||||
echo -n "trap 'kill -SIGUSR1 -$pppid' EXIT SIGINT SIGTERM;" >> $argsf
|
||||
close="; trap - EXIT SIGINT SIGTERM $close"
|
||||
|
||||
export TMUX=$(cut -d , -f 1,2 <<< "$TMUX")
|
||||
mkfifo -m o+w $fifo2
|
||||
if [[ "$opt" =~ "-E" ]]; then
|
||||
cat $fifo2 &
|
||||
if [[ -n "$term" ]] || [[ -t 0 ]]; then
|
||||
cat <<< "\"$fzf\" $opts > $fifo2; out=\$? $close; exit \$out" >> $argsf
|
||||
else
|
||||
mkfifo $fifo1
|
||||
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; out=\$? $close; exit \$out" >> $argsf
|
||||
cat <&0 > $fifo1 &
|
||||
fi
|
||||
|
||||
tmux popup -d "$PWD" $opt "bash $argsf" > /dev/null 2>&1
|
||||
exit $?
|
||||
fi
|
||||
|
||||
mkfifo -m o+w $fifo3
|
||||
if [[ -n "$term" ]] || [[ -t 0 ]]; then
|
||||
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf
|
||||
else
|
||||
mkfifo $fifo1
|
||||
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" >> $argsf
|
||||
cat <&0 > $fifo1 &
|
||||
fi
|
||||
tmux set-window-option synchronize-panes off \;\
|
||||
set-window-option remain-on-exit off \;\
|
||||
split-window -c "$PWD" $opt "bash -c 'exec -a fzf bash $argsf'" $swap \
|
||||
> /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit $?; }
|
||||
cat $fifo2
|
||||
exit "$(cat $fifo3)"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
[ "$1" != '[cancel]' ] && [ "$1" != '[current]' ] && echo $1 | sed 's/: .*$//' | xargs -I{} tmux capture-pane -ep -t {}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select a key binding.'"
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
target=$(tmux list-keys | sed '1s/^/[cancel]\n/' | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
|
||||
[[ "$target" == "[cancel]" || -z "$target" ]] && exit
|
||||
if [[ -n $(echo "$target" | grep -o "copy-mode") && -z $(echo "$target" | grep -o "prefix") ]]; then
|
||||
tmux copy-mode
|
||||
echo "$target" | sed -E 's/^.{46}//g' | xargs tmux
|
||||
else
|
||||
echo "$target" | sed -E 's/^.{46}//g' | xargs tmux
|
||||
fi
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
# get front end list
|
||||
tmux_fzf_menu_origin=$TMUX_FZF_MENU
|
||||
front_end_list=$(echo -e "$tmux_fzf_menu_origin" | sed -n '1p')
|
||||
tmux_fzf_menu_origin=$(echo -e "$tmux_fzf_menu_origin" | sed '1,2d')
|
||||
while [[ $(echo -e "$tmux_fzf_menu_origin" | wc -l | xargs) != "0" && $(echo -e "$tmux_fzf_menu_origin" | wc -l | xargs) != "1" ]]; do
|
||||
front_end_list="$front_end_list\n"$(echo -e "$tmux_fzf_menu_origin" | sed -n '1p')
|
||||
tmux_fzf_menu_origin=$(echo -e "$tmux_fzf_menu_origin" | sed '1,2d')
|
||||
done
|
||||
front_end_list=$(echo -e "$front_end_list" | sed '/^[[:space:]]*$/d')
|
||||
|
||||
target=$(printf "%s\n[cancel]" "$front_end_list" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
|
||||
[[ "$target" == "[cancel]" || -z "$target" ]] && exit
|
||||
# get the next line in $TMUX_FZF_MENU and execute
|
||||
echo -e "$TMUX_FZF_MENU" | sed -n "/$target/{n;p;}" | xargs -I{} tmux -c {}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
current_pane_origin=$(tmux display-message -p '#S:#{window_index}.#{pane_index}: #{window_name}')
|
||||
current_pane=$(tmux display-message -p '#S:#{window_index}.#{pane_index}')
|
||||
|
||||
if [[ -z "$TMUX_FZF_PANE_FORMAT" ]]; then
|
||||
panes=$(tmux list-panes -a -F "#S:#{window_index}.#{pane_index}: [#{window_name}:#{pane_title}] #{pane_current_command} [#{pane_width}x#{pane_height}] [history #{history_size}/#{history_limit}, #{history_bytes} bytes] #{?pane_active,[active],[inactive]}")
|
||||
else
|
||||
panes=$(tmux list-panes -a -F "#S:#{window_index}.#{pane_index}: $TMUX_FZF_PANE_FORMAT")
|
||||
fi
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select an action.'"
|
||||
if [[ -z "$1" ]]; then
|
||||
action=$(printf "switch\nbreak\njoin\nswap\nlayout\nkill\nresize\nrename\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
else
|
||||
action="$1"
|
||||
fi
|
||||
|
||||
[[ "$action" == "[cancel]" || -z "$action" ]] && exit
|
||||
if [[ "$action" == "layout" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select a layout.'"
|
||||
target_origin=$(printf "even-horizontal\neven-vertical\nmain-horizontal\nmain-vertical\ntiled\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
[[ "$target_origin" == "[cancel]" || -z "$target_origin" ]] && exit
|
||||
tmux select-layout "$target_origin"
|
||||
elif [[ "$action" == "resize" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select direction.'"
|
||||
target_origin=$(printf "left\nright\nup\ndown\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
[[ "$target_origin" == "[cancel]" || -z "$target_origin" ]] && exit
|
||||
if [[ "$target_origin" == "left" || "$target_origin" == "right" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Cells to be adjusted.'"
|
||||
size=$(printf "1\n2\n3\n5\n10\n20\n30\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
[[ "$size" == "[cancel]" || -z "$size" ]] && exit
|
||||
if [[ "$target_origin" == "left" ]]; then
|
||||
tmux resize-pane -L "$size"
|
||||
else
|
||||
tmux resize-pane -R "$size"
|
||||
fi
|
||||
elif [[ "$target_origin" == "up" || "$target_origin" == "down" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Lines to be adjusted.'"
|
||||
size=$(printf "1\n2\n3\n5\n10\n15\n20\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
[[ "$size" == "[cancel]" || -z "$size" ]] && exit
|
||||
if [[ "$target_origin" == "up" ]]; then
|
||||
tmux resize-pane -U "$size"
|
||||
else
|
||||
tmux resize-pane -D "$size"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if [[ "$action" == "join" || "$action" == "kill" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target pane(s). Press TAB to mark multiple items.'"
|
||||
else
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target pane.'"
|
||||
fi
|
||||
if [[ "$action" == "switch" || "$action" == "join" ]]; then
|
||||
panes=$(echo "$panes" | grep -v "^$current_pane")
|
||||
target_origin=$(printf "%s\n[cancel]" "$panes" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
else
|
||||
target_origin=$(printf "[current]\n%s\n[cancel]" "$panes" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
target_origin=$(echo "$target_origin" | sed -E "s/\[current\]/$current_pane_origin/")
|
||||
fi
|
||||
[[ "$target_origin" == "[cancel]" || -z "$target_origin" ]] && exit
|
||||
target=$(echo "$target_origin" | sed 's/: .*//')
|
||||
if [[ "$action" == "switch" ]]; then
|
||||
echo "$target" | sed -E 's/:.*//g' | xargs -I{} tmux switch-client -t {}
|
||||
echo "$target" | sed -E 's/\..*//g' | xargs -I{} tmux select-window -t {}
|
||||
echo "$target" | xargs -I{} tmux select-pane -t {}
|
||||
elif [[ "$action" == "kill" ]]; then
|
||||
echo "$target" | sort -r | xargs -I{} tmux kill-pane -t {}
|
||||
elif [[ "$action" == "swap" ]]; then
|
||||
panes=$(echo "$panes" | grep -v "^$target")
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select another target pane.'"
|
||||
target_swap_origin=$(printf "%s\n[cancel]" "$panes" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
[[ "$target_swap_origin" == "[cancel]" || -z "$target_swap_origin" ]] && exit
|
||||
target_swap=$(echo "$target_swap_origin" | sed 's/: .*//')
|
||||
tmux swap-pane -s "$target" -t "$target_swap"
|
||||
elif [[ "$action" == "join" ]]; then
|
||||
echo "$target" | sort -r | xargs -I{} tmux move-pane -s {}
|
||||
elif [[ "$action" == "break" ]]; then
|
||||
cur_ses=$(tmux display-message -p | sed -e 's/^.//' -e 's/].*//')
|
||||
last_win_num=$(tmux list-windows | sort -nr | head -1 | sed 's/:.*//')
|
||||
((last_win_num_after = last_win_num + 1))
|
||||
tmux break-pane -s "$target" -t "$cur_ses":"$last_win_num_after"
|
||||
elif [[ "$action" == "rename" ]]; then
|
||||
tmux command-prompt -I "select-pane -t ${target} -T "
|
||||
fi
|
||||
fi
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select an action.'"
|
||||
if [[ -z "$1" ]]; then
|
||||
if [ -x "$(command -v pstree)" ]; then
|
||||
action=$(printf "display\ntree\nterminate\nkill\ninterrupt\ncontinue\nstop\nquit\nhangup\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
else
|
||||
action=$(printf "display\nterminate\nkill\ninterrupt\ncontinue\nstop\nquit\nhangup\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
fi
|
||||
else
|
||||
action="$1"
|
||||
fi
|
||||
|
||||
[[ "$action" == "[cancel]" || -z "$action" ]] && exit
|
||||
|
||||
content_raw="$(ps aux)"
|
||||
header=$(echo "$content_raw" | head -n 1)
|
||||
content=$(echo "$content_raw" | sed 1d)
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='$header'"
|
||||
ps_selected=$(printf "[cancel]\n$content" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
[[ "$ps_selected" == "[cancel]" || -z "$ps_selected" ]] && exit
|
||||
pid=$(echo "$ps_selected" | awk -F ' ' '{print $2}')
|
||||
user=$(echo "$ps_selected" | awk -F ' ' '{print $1}')
|
||||
_kill() { #{{{ _kill SIG PID USER
|
||||
if [[ "$3" == "$(whoami)" ]]; then
|
||||
kill -s $1 $2
|
||||
else
|
||||
if [ -x "$(command -v sudo)" ]; then
|
||||
tmux split-window -v -p 30 -b -c '#{pane_current_path}' "bash -c 'sudo kill -s $1 $2'"
|
||||
elif [ -x "$(command -v doas)" ]; then
|
||||
tmux split-window -v -p 30 -b -c '#{pane_current_path}' "bash -c 'doas kill -s $1 $2'"
|
||||
fi
|
||||
fi
|
||||
} #}}}
|
||||
if [[ "$action" == "display" ]]; then
|
||||
if [[ "$(uname)" == "Linux" ]]; then
|
||||
tmux split-window -v -p 50 -b -c '#{pane_current_path}' "top -p $pid"
|
||||
else
|
||||
tmux split-window -v -p 50 -b -c '#{pane_current_path}' "top -pid $pid"
|
||||
fi
|
||||
elif [[ "$action" == "tree" ]]; then
|
||||
pstree -p "$pid"
|
||||
elif [[ "$action" == "terminate" ]]; then
|
||||
_kill TERM $pid $user
|
||||
elif [[ "$action" == "kill" ]]; then
|
||||
_kill KILL $pid $user
|
||||
elif [[ "$action" == "interrupt" ]]; then
|
||||
_kill INT $pid $user
|
||||
elif [[ "$action" == "continue" ]]; then
|
||||
_kill CONT $pid $user
|
||||
elif [[ "$action" == "stop" ]]; then
|
||||
_kill STOP $pid $user
|
||||
elif [[ "$action" == "quit" ]]; then
|
||||
_kill QUIT $pid $user
|
||||
elif [[ "$action" == "hangup" ]]; then
|
||||
_kill HUP $pid $user
|
||||
fi
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
current_session=$(tmux display-message -p | sed -e 's/^\[//' -e 's/\].*//')
|
||||
if [[ -z "$TMUX_FZF_SESSION_FORMAT" ]]; then
|
||||
sessions=$(tmux list-sessions | grep -v "^$current_session: ")
|
||||
else
|
||||
sessions=$(tmux list-sessions -F "#S: $TMUX_FZF_SESSION_FORMAT" | grep -v "^$current_session: ")
|
||||
fi
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select an action.'"
|
||||
if [[ -z "$1" ]]; then
|
||||
action=$(printf "switch\nnew\nrename\ndetach\nkill\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
else
|
||||
action="$1"
|
||||
fi
|
||||
|
||||
[[ "$action" == "[cancel]" || -z "$action" ]] && exit
|
||||
if [[ "$action" != "detach" ]]; then
|
||||
if [[ "$action" == "new" ]]; then
|
||||
tmux split-window -v -p 30 -b -c '#{pane_current_path}' \
|
||||
'printf "Session Name: " && read session_name && tmux new-session -d -s ${session_name} && tmux switch-client -t ${session_name}'
|
||||
exit
|
||||
fi
|
||||
if [[ "$action" == "kill" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target session(s). Press TAB to mark multiple items.'"
|
||||
else
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target session.'"
|
||||
fi
|
||||
if [[ "$action" == "switch" ]]; then
|
||||
target_origin=$(printf "%s\n[cancel]" "$sessions" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
else
|
||||
target_origin=$(printf "[current]\n%s\n[cancel]" "$sessions" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
target_origin=$(echo "$target_origin" | sed -E "s/\[current\]/$current_session:/")
|
||||
fi
|
||||
else
|
||||
tmux_attached_sessions=$(tmux list-sessions | grep 'attached' | grep -o '^[[:alpha:][:digit:]_-]*:' | sed 's/.$//g')
|
||||
sessions=$(echo "$sessions" | grep "^$tmux_attached_sessions")
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target session(s). Press TAB to mark multiple items.'"
|
||||
target_origin=$(printf "[current]\n%s\n[cancel]" "$sessions" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
target_origin=$(echo "$target_origin" | sed -E "s/\[current\]/$current_session:/")
|
||||
fi
|
||||
[[ "$target_origin" == "[cancel]" || -z "$target_origin" ]] && exit
|
||||
target=$(echo "$target_origin" | sed -e 's/:.*$//')
|
||||
if [[ "$action" == "switch" ]]; then
|
||||
tmux switch-client -t "$target"
|
||||
elif [[ "$action" == "detach" ]]; then
|
||||
echo "$target" | xargs -I{} tmux detach -s "{}"
|
||||
elif [[ "$action" == "kill" ]]; then
|
||||
echo "$target" | sort -r | xargs -I{} tmux kill-session -t "{}"
|
||||
elif [[ "$action" == "rename" ]]; then
|
||||
tmux command-prompt -I "rename-session -t $target "
|
||||
fi
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$CURRENT_DIR/.envs"
|
||||
|
||||
current_window_origin=$(tmux display-message -p '#S:#I: #{window_name}')
|
||||
current_window=$(tmux display-message -p '#S:#I:')
|
||||
|
||||
if [[ -z "$TMUX_FZF_WINDOW_FILTER" ]]; then
|
||||
window_filter="-a"
|
||||
else
|
||||
window_filter="-f \"$TMUX_FZF_WINDOW_FILTER\""
|
||||
fi
|
||||
|
||||
if [[ -z "$TMUX_FZF_WINDOW_FORMAT" ]]; then
|
||||
windows=$(tmux list-windows $window_filter)
|
||||
else
|
||||
windows=$(tmux list-windows $window_filter -F "#S:#{window_index}: $TMUX_FZF_WINDOW_FORMAT")
|
||||
fi
|
||||
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select an action.'"
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
action=$(printf "switch\nlink\nmove\nswap\nrename\nkill\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
|
||||
else
|
||||
action="$1"
|
||||
fi
|
||||
|
||||
[[ "$action" == "[cancel]" || -z "$action" ]] && exit
|
||||
if [[ "$action" == "link" ]]; then
|
||||
cur_ses=$(tmux display-message -p | sed -e 's/^.//' -e 's/].*//')
|
||||
last_win_num=$(tmux list-windows | sort -r | sed '2,$d' | sed 's/:.*//')
|
||||
windows=$(echo "$windows" | grep -v "^$cur_ses")
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select source window.'"
|
||||
src_win_origin=$(printf "%s\n[cancel]" "$windows" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
[[ "$src_win_origin" == "[cancel]" || -z "$src_win_origin" ]] && exit
|
||||
src_win=$(echo "$src_win_origin" | sed 's/: .*//')
|
||||
tmux link-window -a -s "$src_win" -t "$cur_ses"
|
||||
elif [[ "$action" == "move" ]]; then
|
||||
cur_ses=$(tmux display-message -p | sed -e 's/^.//' -e 's/].*//')
|
||||
last_win_num=$(tmux list-windows | sort -r | sed '2,$d' | sed 's/:.*//')
|
||||
windows=$(echo "$windows" | grep -v "^$cur_ses")
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select source window.'"
|
||||
src_win_origin=$(printf "%s\n[cancel]" "$windows" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
[[ "$src_win_origin" == "[cancel]" || -z "$src_win_origin" ]] && exit
|
||||
src_win=$(echo "$src_win_origin" | sed 's/: .*//')
|
||||
tmux move-window -a -s "$src_win" -t "$cur_ses"
|
||||
else
|
||||
if [[ "$action" == "kill" ]]; then
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target window(s). Press TAB to mark multiple items.'"
|
||||
else
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select target window.'"
|
||||
fi
|
||||
if [[ "$action" != "switch" ]]; then
|
||||
target_origin=$(printf "[current]\n%s\n[cancel]" "$windows" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
target_origin=$(echo "$target_origin" | sed -E "s/\[current\]/$current_window_origin/")
|
||||
else
|
||||
windows=$(echo "$windows" | grep -v "^$current_window")
|
||||
target_origin=$(printf "%s\n[cancel]" "$windows" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
fi
|
||||
[[ "$target_origin" == "[cancel]" || -z "$target_origin" ]] && exit
|
||||
target=$(echo "$target_origin" | sed 's/: .*//')
|
||||
if [[ "$action" == "kill" ]]; then
|
||||
echo "$target" | sort -r | xargs -I{} tmux unlink-window -k -t {}
|
||||
elif [[ "$action" == "rename" ]]; then
|
||||
tmux command-prompt -I "rename-window -t $target "
|
||||
elif [[ "$action" == "swap" ]]; then
|
||||
windows=$(echo "$windows" | grep -v "^$target")
|
||||
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select another target window.'"
|
||||
target_swap_origin=$(printf "%s\n[cancel]" "$windows" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS $TMUX_FZF_PREVIEW_OPTIONS")
|
||||
[[ "$target_swap_origin" == "[cancel]" || -z "$target_swap_origin" ]] && exit
|
||||
target_swap=$(echo "$target_swap_origin" | sed 's/: .*//')
|
||||
tmux swap-pane -s "$target" -t "$target_swap"
|
||||
elif [[ "$action" == "switch" ]]; then
|
||||
echo "$target" | sed 's/:.*//g' | xargs -I{} tmux switch-client -t {}
|
||||
echo "$target" | xargs -I{} tmux select-window -t {}
|
||||
fi
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue