addet blesh

This commit is contained in:
pika 2024-08-18 03:40:38 +02:00
parent 58205a50b9
commit 8c8d8e9962
302 changed files with 74275 additions and 0 deletions

View file

@ -0,0 +1,180 @@
# ble/contrib/integration/bash-preexec.bash (C) 2022-2023, akinomyoga
## @arr[in] precmd_functions
## @arr[in] preexec_functions
## The functions registered to these arrays are executed on PRECMD and
## PREEXEC hooks, respectively.
##
## @fn[in] precmd
## @fn[in] preexec
## If these functions are defined, they are executed on PRECMD and PREEXEC
## hooks, respectively, through "precmd_functions" and "preexec_functions".
##
##
## * Integration with bash-preexec.sh (https://github.com/rcaloras/bash-preexec)
##
## Although this script works without bash-preexec, it provides a better
## integration with bash-preexec when bash-preexec is loaded. The
## integration relies on the following public API of bash-preexec.
##
## @fn __bp_precmd_invoke_functions lastexit lastarg
## @fn __bp_preexec_invoke_functions lastexit lastarg this_command
## @fn __bp_uninstall
## @var __bp_trapdebug_string
## @var __bp_install_string
function ble/contrib/integration:bash-preexec/add-convenience-functions {
ble/array#remove precmd_functions precmd
ble/array#remove preexec_functions preexec
ble/array#unshift precmd_functions precmd
ble/array#unshift preexec_functions preexec
}
function ble/contrib/integration:bash-preexec/precmd.hook {
local _ble_local_lastexit=$? _ble_local_lastarg=$_
# Emulate bash-preexec variables
__bp_last_ret_value=$_ble_local_lastexit
__bp_last_argument_prev_command=$_ble_local_lastarg
BP_PIPESTATUS=("${BLE_PIPESTATUS[@]}")
local __bp_inside_precmd=1
# local __bp_blesh_invoking_through_blesh=1 # XXX
if ble/is-function __bp_precmd_invoke_functions; then
__bp_precmd_invoke_functions "$_ble_local_lastexit" "$_ble_local_lastarg"
else
# For older bash-preexec.sh / without bash-preexec.sh
local _ble_local_hook
for _ble_local_hook in "${precmd_functions[@]}"; do
if ble/bin#has "$_ble_local_hook"; then
ble/util/setexit "$_ble_local_lastexit" "$_ble_local_lastarg"
"$_ble_local_hook"
fi
done
fi
}
function ble/contrib/integration:bash-preexec/preexec.hook {
local _ble_local_lastexit=$? _ble_local_lastarg=$_ _ble_local_command=$1
# Emulate bash-preexec variables
local __bp_inside_preexec=1
# local __bp_blesh_invoking_through_blesh=1 # XXX
if ble/is-function __bp_preexec_invoke_functions; then
__bp_preexec_invoke_functions "$_ble_local_lastexit" "$_ble_local_lastarg"
else
# For older bash-preexec.sh / without bash-preexec.sh
local _ble_local_hook
for _ble_local_hook in "${preexec_functions[@]}"; do
if ble/bin#has "$_ble_local_hook"; then
ble/util/setexit "$_ble_local_lastexit" "$_ble_local_lastarg"
"$_ble_local_hook" "$_ble_local_command"
fi
done
fi
}
## @fn ble/contrib/integration:bash-preexec/attach.hook
## Remove bash-preexec hooks
function ble/contrib/integration:bash-preexec/attach.hook {
local BP_TRAPDEBUG_STRING=${__bp_trapdebug_string:-'__bp_preexec_invoke_exec "$_"'}
# Remove bash-preexec preexec hook in builtin DEBUG trap.
local trap_string q="'" Q="'\''"
ble/util/assign trap_string 'builtin trap -p DEBUG'
if [[ $trap_string == "trap -- '${BP_TRAPDEBUG_STRING//$q/$Q}' DEBUG" ]]; then
if [[ ${__bp_trap_string-} ]]; then
builtin eval -- "builtin $__bp_trap_string"
else
builtin trap - DEBUG
fi
fi
if ble/is-function __bp_uninstall; then
__bp_uninstall
else
# For older bash-preexec.sh
local BP_INSTALL_STRING=${__bp_install_string:-$'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install'}
local BP_PROMPT_COMMAND_PREFIX=__bp_precmd_invoke_cmd
local BP_PROMPT_COMMAND_SUFFIX=__bp_interactive_mode
# Remove __bp_install hook from PROMPT_COMMAND
if [[ ${PROMPT_COMMAND-} == *"$__bp_install_string"* ]]; then
PROMPT_COMMAND="${PROMPT_COMMAND//$BP_INSTALL_STRING[;$'\n']}" # Edge case of appending to PROMPT_COMMAND
PROMPT_COMMAND="${PROMPT_COMMAND//$BP_INSTALL_STRING}"
fi
# Remove precmd hook from PROMPT_COMMAND
local i prompt_command
for i in "${!PROMPT_COMMAND[@]}"; do
prompt_command=${PROMPT_COMMAND[i]}
case $prompt_command in
("$BP_PROMPT_COMMAND_PREFIX"|"$BP_PROMPT_COMMAND_SUFFIX")
prompt_command= ;;
(*)
prompt_command=${prompt_command/#"$BP_PROMPT_COMMAND_PREFIX"$'\n'/$'\n'}
prompt_command=${prompt_command%$'\n'"$BP_PROMPT_COMMAND_SUFFIX"}
prompt_command=${prompt_command#$'\n'}
esac
PROMPT_COMMAND[i]=$prompt_command
done
# Remove preexec hook in the DEBUG trap
local q="'" Q="'\''" trap_string
ble/util/assign trap_string 'trap -p DEBUG'
if [[ $trap_string == "trap -- '${BP_TRAPDEBUG_STRING//$q/$Q}' DEBUG" ]]; then
if [[ ${__bp_trap_string-} ]]; then
builtin eval -- "$__bp_trap_string"
else
trap - DEBUG
fi
fi
fi
}
ble/function#trace ble/contrib/integration:bash-preexec/attach.hook
## @fn ble/contrib/integration:bash-preexec/detach.hook
function ble/contrib/integration:bash-preexec/detach.hook {
# Reinstall bash-preexec hooks
local BP_INSTALL_STRING=${__bp_install_string-}
[[ ! $BP_INSTALL_STRING ]] && ble/is-function __bp_install &&
BP_INSTALL_STRING=$'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install'
builtin eval -- "$__bp_install_string"
# Note: 重複して登録される (古い bash-preexec.sh) かもしれないし、全
# く登録されない (bash-preexec.sh をロードしていない時) かもしれない
# ので、ble.sh 側で末尾で一回呼び出す形に修正する。
ble/contrib/integration:bash-preexec/add-convenience-functions
}
ble/contrib/integration:bash-preexec/add-convenience-functions
blehook PRECMD!=ble/contrib/integration:bash-preexec/precmd.hook
blehook PREEXEC!=ble/contrib/integration:bash-preexec/preexec.hook
blehook ATTACH!=ble/contrib/integration:bash-preexec/attach.hook
blehook DETACH!=ble/contrib/integration:bash-preexec/detach.hook
if [[ ${bash_preexec_imported-${__bp_imported-}} ]]; then
ble/contrib/integration:bash-preexec/attach.hook
fi
# prevent bash-preexec.sh to be loaded
blehook ATTACH-=ble/contrib/integration:bash-preexec/loader
blehook POSTEXEC-=ble/contrib/integration:bash-preexec/loader
bash_preexec_imported=defined
__bp_imported=defined
# XXX: 以下は uninstall で削除しきれなかった時の為の保険。今の所不要に思われる。
# __bp_blesh_check() {
# if [[ $BLE_ATTACHED && ! ${__bp_blesh_invoking_through_blesh-} ]]; then
# ble/contrib/integration:bash-preexec/attach.hook
# fi
# }
# precmd_function+=(__bp_blesh_check)
# preexec_function+=(__bp_blesh_check)
# Some settings rely on the internal APIs of bash-preexec. For example, iTerm2
# shell integration uses "__bp_set_ret_value" and
# "$__bp_last_argument_prev_command".
function __bp_set_ret_value { return ${1:+"$1"}; }

View file

@ -0,0 +1,62 @@
# ble/contrib/integration/fzf-completion.bash (C) 2020-2023, akinomyoga
ble-import contrib/integration/fzf-initialize
[[ $- == *i* ]] || return 0
# fzf/shell/completion.bash を未ロードの時のみロードする
if ! ble/is-function _fzf_complete; then
if [[ -f $_ble_contrib_fzf_base/completion.bash ]]; then
source "$_ble_contrib_fzf_base/completion.bash"
elif [[ -f $_ble_contrib_fzf_base/shell/completion.bash ]]; then
source "$_ble_contrib_fzf_base/shell/completion.bash"
elif [[ $_ble_contrib_fzf_base == */share/fzf && -f /etc/bash_completion.d/fzf ]]; then
source /etc/bash_completion.d/fzf
fi
fi
# clear blesh completer for cd
blehook/eval-after-load complete 'builtin unset -f ble/cmdinfo/complete:cd'
# patch fzf functions
ble/function#advice around __fzf_generic_path_completion _fzf_complete.advice
ble/function#advice around _fzf_complete _fzf_complete.advice
ble/function#advice around _fzf_complete_kill _fzf_complete.advice
function _fzf_complete.advice {
if [[ ! ${_ble_attached-} ]]; then
ble/function#push caller 'builtin caller ${1+"$(($1+6))"}'
ble/function#advice/do
ble/function#pop caller
return 0
fi
[[ :$comp_type: == *:auto:* || :$comp_type: == *:[maA]:* ]] && return 0
compopt -o ble/syntax-raw
if [[ ! ${_ble_contrib_fzf_comp_words_raw-} ]]; then
local _ble_contrib_fzf_comp_words_raw=1
local COMP_WORDS; COMP_WORDS=("${comp_words[@]}")
local COMP_CWORD=$comp_cword
local COMP_LINE=$comp_line COMP_POINT=$comp_point
fi
ble/function#push printf '[[ $1 == "\e[5n" ]] || builtin printf "$@"'
ble/function#push caller 'builtin caller ${1+"$(($1+6))"}'
ble/term/leave-for-widget
if [[ ${ADVICE_WORDS[0]} == _fzf_complete ]]; then
ble/function#advice/do >&"${_ble_util_fd_tty_stdout:-1}" 2>&"${_ble_util_fd_tty_stderr:-2}"
else
ble/function#advice/do >&"${_ble_util_fd_tty_stdout:-1}" 2>&"${_ble_util_fd_tty_stderr:-2}" <&"${_ble_util_fd_tty_stdin:-0}"
fi
ble/term/enter-for-widget
ble/function#pop caller
ble/function#pop printf
ble/textarea#invalidate
# 単一候補生成の場合は他の候補 (sabbrev 等) を消去して単一確定させる
if ((ADVICE_EXIT==0&&${#COMPREPLY[@]}==1)); then
compopt -o ble/no-default
ble/complete/candidates/clear
[[ $old_cand_count ]] &&
! ble/variable#is-global old_cand_count &&
old_cand_count=0
fi
}

View file

@ -0,0 +1,322 @@
# Copyright (c) 2016, 2022 Junegunn Choi
# ble/contrib/integration/fzf-git.bash (C) 2020, 2023, akinomyoga
#
# 2020-04-16 https://gist.github.com/junegunn/8b572b8d4b5eddd8b85e5f4d40f17236 (Revision 2019-03-14)
# 2023-06-30 https://gist.github.com/junegunn/8b572b8d4b5eddd8b85e5f4d40f17236 (Revision 2022-08-16)
# 2023-06-30 https://github.com/junegunn/fzf-git.sh/commit/4bc0323b4822b3426989863996cc266c52c7f25a
# 2023-06-30 https://github.com/junegunn/fzf-git.sh/commit/b6192ec86609afea761c7d3954f9b539a512dc80
# 2023-11-09 https://github.com/junegunn/fzf-git.sh/blob/aacab4ae557657e0f9de288d688f312a28b86d21/fzf-git.sh
if [[ $- != *i* ]]; then
if (($# == 1)); then
function ble/contrib/integration:fzf-git/sub:branches {
git branch "$@" --sort=-committerdate --sort=-HEAD --format=$'%(HEAD) %(color:yellow)%(refname:short) %(color:green)(%(committerdate:relative))\t%(color:blue)%(subject)%(color:reset)' --color=always | column -ts$'\t'
}
function ble/contrib/integration:fzf-git/sub:refs {
git for-each-ref --sort=-creatordate --sort=-HEAD --color=always --format=$'%(refname) %(color:green)(%(creatordate:relative))\t%(color:blue)%(subject)%(color:reset)' |
builtin eval -- "$1" |
sed 's#^refs/remotes/#\x1b[95mremote-branch\t\x1b[33m#; s#^refs/heads/#\x1b[92mbranch\t\x1b[33m#; s#^refs/tags/#\x1b[96mtag\t\x1b[33m#; s#refs/stash#\x1b[91mstash\t\x1b[33mrefs/stash#' |
column -ts$'\t'
}
case $1 in
(branches)
printf '%s\n' $'CTRL-O (open in browser) ALT-A (show all branches)\n'
ble/contrib/integration:fzf-git/sub:branches
;;
(all-branches)
printf '%s\n' $'CTRL-O (open in browser)\n'
ble/contrib/integration:fzf-git/sub:branches -a
;;
(refs)
printf '%s\n' $'CTRL-O (open in browser) ALT-E (examine in editor) ALT-A (show all refs)\n'
ble/contrib/integration:fzf-git/sub:refs 'grep -v ^refs/remotes'
;;
(all-refs)
printf '%s\n' $'CTRL-O (open in browser) ALT-E (examine in editor)\n'
ble/contrib/integration:fzf-git/sub:refs 'cat'
;;
(nobeep) ;;
(*) exit 1 ;;
esac
elif (($# > 1)); then
set -e
branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [[ $branch = HEAD ]]; then
branch=$(git describe --exact-match --tags 2> /dev/null || git rev-parse --short HEAD)
fi
# Only supports GitHub for now
case $1 in
(commit)
hash=$(grep -o "[a-f0-9]\{7,\}" <<< "$2")
path=/commit/$hash
;;
(branch|remote-branch)
branch=$(sed 's/^[* ]*//' <<< "$2" | cut -d' ' -f1)
remote=$(git config branch."${branch}".remote || printf 'origin\n')
branch=${branch#$remote/}
path=/tree/$branch
;;
(remote)
remote=$2
path=/tree/$branch
;;
(file) path=/blob/$branch/$(git rev-parse --show-prefix)$2 ;;
(tag) path=/releases/tag/$2 ;;
(*) exit 1 ;;
esac
remote=${remote:-$(git config branch."${branch}".remote || printf 'origin\n')}
remote_url=$(git remote get-url "$remote" 2> /dev/null || printf '%s\n' "$remote")
if [[ $remote_url =~ ^git@ ]]; then
url=${remote_url%.git}
url=${url#git@}
url=https://${url/://}
elif [[ $remote_url =~ ^http ]]; then
url=${remote_url%.git}
fi
case $(uname -s) in
(Darwin) open "$url$path" ;;
(*) xdg-open "$url$path" ;;
esac
fi
exit 0
fi
#------------------------------------------------------------------------------
ble-import contrib/integration/fzf-initialize
[[ $- == *i* ]] || return 0
## @fn ble/contrib/integration:fzf-git/initialize bash_source
## @param[in] bash_source
## @var[out] __fzf_git
function ble/contrib/integration:fzf-git/initialize {
local ret
ble/util/readlink "$1"
__fzf_git=$ret
}
ble/contrib/integration:fzf-git/initialize "${BASH_SOURCE[0]:-}"
# GIT heart FZF
# -------------
#------------------------------------------------------------------------------
# Redefine this function to change the options
_fzf_git_fzf() {
fzf-tmux -p80%,60% -- \
--layout=reverse --multi --height=50% --min-height=20 --border \
--border-label-pos=2 \
--color='header:italic:underline,label:blue' \
--preview-window='right,50%,border-left' \
--bind='ctrl-/:change-preview-window(down,50%,border-top|hidden|)' "$@"
}
function ble/contrib/integration:fzf-git/fzf {
[[ $_ble_term_state == internal ]] && ble/term/leave-for-widget
_fzf_git_fzf "$@"
local ext=$?
[[ $_ble_term_state == internal ]] && ble/term/enter-for-widget
return "$ext"
}
_fzf_git_check() {
git rev-parse HEAD > /dev/null 2>&1 && return 0
[[ -n $TMUX ]] && tmux display-message "Not in a git repository"
return 1
}
if [[ -z $_fzf_git_cat ]]; then
# Sometimes bat is installed as batcat
export _fzf_git_cat="cat"
_fzf_git_bat_options="--style='${BAT_STYLE:-full}' --color=always --pager=never"
if command -v batcat > /dev/null; then
_fzf_git_cat="batcat $_fzf_git_bat_options"
elif command -v bat > /dev/null; then
_fzf_git_cat="bat $_fzf_git_bat_options"
fi
fi
_fzf_git_files() {
_fzf_git_check || return "$?"
(git -c color.status=always status --short --no-branch
git ls-files | grep -vxFf <(git status -s | grep '^[^?]' | cut -c4-; ble/util/print :) | sed 's/^/ /') |
ble/contrib/integration:fzf-git/fzf -m --ansi --nth 2..,.. \
--border-label '📁 Files' \
--header $'CTRL-O (open in browser) ALT-E (open in editor)\n\n' \
--bind "ctrl-o:execute-silent:bash $__fzf_git file {-1}" \
--bind "alt-e:execute:${EDITOR:-vim} {-1} > /dev/tty" \
--preview "git diff --no-ext-diff --color=always -- {-1} | sed 1,4d; $_fzf_git_cat {-1}" "$@" |
cut -c4- | sed 's/.* -> //'
}
_fzf_git_branches() {
_fzf_git_check || return "$?"
bash "$__fzf_git" branches |
ble/contrib/integration:fzf-git/fzf --ansi \
--border-label '🌲 Branches' \
--header-lines 2 \
--tiebreak begin \
--preview-window down,border-top,40% \
--color hl:underline,hl+:underline \
--no-hscroll \
--bind 'ctrl-/:change-preview-window(down,70%|hidden|)' \
--bind "ctrl-o:execute-silent:bash $__fzf_git branch {}" \
--bind "alt-a:change-prompt(🌳 All branches> )+reload:bash \"$__fzf_git\" all-branches" \
--preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1)' "$@" |
sed 's/^..//' | cut -d' ' -f1
}
_fzf_git_tags() {
_fzf_git_check || return "$?"
git tag --sort -version:refname |
ble/contrib/integration:fzf-git/fzf --preview-window right,70% \
--border-label '📛 Tags' \
--header $'CTRL-O (open in browser)\n\n' \
--bind "ctrl-o:execute-silent:bash $__fzf_git tag {}" \
--preview 'git show --color=always {}' "$@"
}
_fzf_git_hashes() {
_fzf_git_check || return "$?"
git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always |
ble/contrib/integration:fzf-git/fzf --ansi --no-sort --bind 'ctrl-s:toggle-sort' \
--border-label '🍡 Hashes' \
--header $'CTRL-O (open in browser) CTRL-D (diff) CTRL-S (toggle sort)\n\n' \
--bind "ctrl-o:execute-silent:bash $__fzf_git commit {}" \
--bind 'ctrl-d:execute:grep -o "[a-f0-9]\{7,\}" <<< {} | head -n 1 | xargs git diff > /dev/tty' \
--color hl:underline,hl+:underline \
--preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | head -n 1 | xargs git show --color=always' "$@" |
awk 'match($0, /[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]*/) { print substr($0, RSTART, RLENGTH) }'
}
_fzf_git_remotes() {
_fzf_git_check || return "$?"
git remote -v | awk '{print $1 "\t" $2}' | uniq |
ble/contrib/integration:fzf-git/fzf --tac \
--border-label '📡 Remotes' \
--header $'CTRL-O (open in browser)\n\n' \
--bind "ctrl-o:execute-silent:bash $__fzf_git remote {1}" \
--preview-window right,70% \
--preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" {1}/"$(git rev-parse --abbrev-ref HEAD)"' "$@" |
cut -d$'\t' -f1
}
_fzf_git_stashes() {
_fzf_git_check || return "$?"
git stash list | ble/contrib/integration:fzf-git/fzf \
--border-label '🥡 Stashes' \
--header $'CTRL-X (drop stash)\n\n' \
--bind 'ctrl-x:execute-silent(git stash drop {1})+reload(git stash list)' \
-d: --preview 'git show --color=always {1}' "$@" |
cut -d: -f1
}
_fzf_git_lreflogs() {
_fzf_git_check || return "$?"
git reflog --color=always --format="%C(blue)%gD %C(yellow)%h%C(auto)%d %gs" | ble/contrib/integration:fzf-git/fzf --ansi \
--border-label '📒 Reflogs' \
--preview 'git show --color=always {1}' "$@" |
awk '{print $1}'
}
_fzf_git_each_ref() {
_fzf_git_check || return "$?"
bash "$__fzf_git" refs | ble/contrib/integration:fzf-git/fzf --ansi \
--nth 2,2.. \
--tiebreak begin \
--border-label '☘️ Each ref' \
--header-lines 2 \
--preview-window down,border-top,40% \
--color hl:underline,hl+:underline \
--no-hscroll \
--bind 'ctrl-/:change-preview-window(down,70%|hidden|)' \
--bind "ctrl-o:execute-silent:bash $__fzf_git {1} {2}" \
--bind "alt-e:execute:${EDITOR:-vim} <(git show {2}) > /dev/tty" \
--bind "alt-a:change-prompt(🍀 Every ref> )+reload:bash \"$__fzf_git\" all-refs" \
--preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" {2}' "$@" |
awk '{print $2}'
}
#------------------------------------------------------------------------------
# export FZF_DEFAULT_OPTS=--no-unicode
: "${_ble_contrib_fzf_git_config=key-binding}"
# original
function ble/contrib:integration/fzf-git/type:original/init {
ble/builtin/bind '"\er": redraw-current-line'
}
function ble/contrib:integration/fzf-git/type:original {
local binding='"\C-g\C-'$1'": "$(_fzf_git_'$2')\e\C-e\er"'
ble/builtin/bind "$binding"
}
# function ble/contrib:integration/fzf-git/type:original {
# local binding='"\C-g\C-'$1'": "$(_fzf_git_'$2')\M-\C-e\M-\C-l"'
# bind "$binding"
# }
function ble/widget/fzf-git {
ble/widget/insert-string "$(_fzf_git_$1)"
ble/textarea#invalidate
}
# key-binding
function ble/contrib:integration/fzf-git/type:key-binding {
ble-bind -f "C-g C-$1" "fzf-git $2"
}
# sabbrev
function ble/contrib:integration/fzf-git/type:sabbrev/init {
function fzf-git.sabbrev {
COMPREPLY=$(_fzf_git_$1)
ble/textarea#invalidate
}
}
function ble/contrib:integration/fzf-git/type:sabbrev {
ble-sabbrev -m "g$1"="fzf-git.sabbrev $2"
}
# arpeggio
function ble/contrib:integration/fzf-git/type:arpeggio/init {
ble-import 'lib/vim-arpeggio.sh'
}
function ble/contrib:integration/fzf-git/type:arpeggio {
ble/lib/vim-arpeggio.sh/bind -f "g$1" "fzf-git $2"
}
# old-functions
function ble/contrib:integration/fzf-git/type:old-functions/init {
function is_in_git_repo { _fzf_git_check "$@"; }
function fzf-down { ble/contrib/integration:fzf-git/fzf "$@"; }
}
function ble/contrib:integration/fzf-git/type:old-functions {
# Note: To suppress duplicate adjustment of the terminal states, we override
# "_ble_term_state" with the temporary environment. I.e., when fzf is called
# through these old function names, we never adjust the terminal states.
builtin eval "function g$1 { _ble_term_state= _fzf_git_$2 \"\$@\"; }"
}
function ble/contrib:integration/fzf-git/initialize {
local type
for type in original key-binding sabbrev arpeggio old-functions; do
[[ :$_ble_contrib_fzf_git_config: == *:"$type":* ]] || continue
ble/function#try ble/contrib:integration/fzf-git/type:"$type"/init
ble/contrib:integration/fzf-git/type:"$type" f files
ble/contrib:integration/fzf-git/type:"$type" b branches
ble/contrib:integration/fzf-git/type:"$type" t tags
ble/contrib:integration/fzf-git/type:"$type" h hashes
ble/contrib:integration/fzf-git/type:"$type" r remotes
ble/contrib:integration/fzf-git/type:"$type" s stashes
ble/contrib:integration/fzf-git/type:"$type" l lreflogs
ble/contrib:integration/fzf-git/type:"$type" e each_ref
done
builtin unset -f "$FUNCNAME"
}
ble/contrib:integration/fzf-git/initialize

View file

@ -0,0 +1,53 @@
# ble/contrib/integration/fzf-initialize.bash (C) 2020-2023, akinomyoga
# Usage: Please write the following lines in blerc
#
# ```bash
# _ble_contrib_fzf_base=/path/to/fzf-base-directory
# ble-import -d integration/fzf-initialize
# ```
function ble/contrib/integration:fzf-completion/initialize {
if [[ -d $_ble_contrib_fzf_base ]]; then
if [[ -d $_ble_contrib_fzf_base/bin && :$PATH: != *:"$_ble_contrib_fzf_base/bin":* ]]; then
export PATH="${PATH:+${PATH}:}$_ble_contrib_fzf_base/bin"
fi
if ! ble/bin#has fzf; then
ble/util/print 'ble/contrib/integration:fzf-initialize: "fzf" not found.' >&2
return 1
fi
else
local path
if ! ble/bin#get-path fzf; then
ble/util/print 'ble/contrib/integration:fzf: "fzf" not found.' >&2
return 1
fi
local ret
ble/util/readlink "$path"
ret=${ret%/*} # fzf, fzf-linux_amd64, etc.
ret=${ret%/bin} # repo/bin/
ret=${ret%/target} # repo/target (compile directory)
if [[ -s $ret/shell/key-bindings.bash ]]; then
_ble_contrib_fzf_base=$ret
elif [[ -d $ret/share/fzf/shell ]]; then
_ble_contrib_fzf_base=$ret/share/fzf
elif [[ -s $ret/share/fzf/key-bindings.bash ]]; then
# NixOS package (https://github.com/akinomyoga/blesh-contrib/pull/5#issuecomment-1019394821)
_ble_contrib_fzf_base=$ret/share/fzf
elif [[ -s $ret/share/doc/fzf/examples/key-bindings.bash ]]; then
# Ubuntu fzf package (https://github.com/akinomyoga/blesh-contrib/pull/5#issuecomment-1019394821)
_ble_contrib_fzf_base=$ret/share/doc/fzf/examples
elif [[ -d /usr/share/fzf/shell ]]; then
_ble_contrib_fzf_base=/usr/share/fzf
elif [[ -d /usr/share/doc/fzf/examples/key-bindings.bash ]]; then
# Ubuntu fzf package (https://github.com/akinomyoga/blesh-contrib/pull/5#issuecomment-1019394821)
_ble_contrib_fzf_base=/usr/share/doc/fzf/examples
else
ble/util/print 'ble/contrib/integration:fzf: failed to find "fzf" base directory' >&2
return 1
fi
fi
return 0
}
ble/contrib/integration:fzf-completion/initialize || return 1

View file

@ -0,0 +1,40 @@
# ble/contrib/integration/fzf-key-bindings.bash (C) 2020-2023, akinomyoga
ble-import contrib/integration/fzf-initialize
[[ $- == *i* ]] || return 0
ble/function#push bind :
if [[ -f $_ble_contrib_fzf_base/key-bindings.bash ]]; then
source "$_ble_contrib_fzf_base/key-bindings.bash"
elif [[ -f $_ble_contrib_fzf_base/shell/key-bindings.bash ]]; then
source "$_ble_contrib_fzf_base/shell/key-bindings.bash"
fi
ble/function#pop bind
function ble/contrib/integration:fzf-key-bindings/is-fzf-above-7c447bbd {
local def; ble/function#getdef __fzf_history__
[[ $def == *READLINE_LINE=* ]]
}
# CTRL-T - Paste the selected file path into the command line
ble-bind -m emacs -x C-t fzf-file-widget
ble-bind -m vi_imap -x C-t fzf-file-widget
ble-bind -m vi_nmap -s C-t 'i\C-t'
# CTRL-R - Paste the selected command from history into the command line
ble-bind -m emacs -x C-r fzf-history-widget
ble-bind -m vi_imap -x C-r fzf-history-widget
ble-bind -m vi_nmap -s C-r 'i\C-r'
function fzf-history-widget {
READLINE_LINE=$(history -p "$(__fzf_history__)")
READLINE_POINT=${#READLINE_LINE}
}
((_ble_bash>=40000)) &&
ble/contrib/integration:fzf-key-bindings/is-fzf-above-7c447bbd &&
function fzf-history-widget { __fzf_history__; }
# ALT-C - cd into the selected directory
ble-bind -m emacs -c M-c 'builtin eval -- "$(__fzf_cd__)"'
ble-bind -m vi_imap -c M-c 'builtin eval -- "$(__fzf_cd__)"'
ble-bind -m vi_nmap -c M-c 'builtin eval -- "$(__fzf_cd__)"'

View file

@ -0,0 +1,27 @@
# ble/contrib/integration/nix-completion.bash (C) 2023, akinomyoga
[[ $- == *i* ]] || return 0
function ble/contrib/integration:nix-completion/_complete_nix.advice {
if [[ ${_ble_attached-} && " ${FUNCNAME[*]} " == *" ble/complete/progcomp/.compgen "* && ${COMP_WORDS[0]-} != *[\'\"\\]* ]]; then
local _ble_nix_cmd=${COMP_WORDS[0]-nix} ret
ble/function#push "$_ble_nix_cmd" '
local IFS=$_ble_term_IFS
local -a args; args=("$@")
ble/util/conditional-sync "exec $_ble_nix_cmd \"\${args[@]}\"" \
"! ble/complete/check-cancel <&$_ble_util_fd_tui_stdin" 128 progressive-weight:killall'
ble/function#advice/do
ble/function#pop "$_ble_nix_cmd"
else
ble/function#advice/do
return 0
fi
}
function ble/contrib/integration:nix-completion/adjust {
if ble/is-function _complete_nix; then
ble/function#advice around _complete_nix ble/contrib/integration:nix-completion/_complete_nix.advice
fi
}
ble/contrib/integration:nix-completion/adjust

View file

@ -0,0 +1,61 @@
# ble/contrib/integration/zoxide.bash (C) 2022, akinomyoga
function ble/contrib/integration:zoxide/completion.advice {
if [[ ! ${_ble_attached-} ]]; then
ble/function#advice/do
return 0
fi
[[ :$comp_type: == *:auto:* || :$comp_type: == *:[maA]:* ]] && return 0
compopt -o noquote
ble/term/leave-for-widget
ble/function#advice/do >/dev/null
ble/term/enter-for-widget
ble/textarea#invalidate
# 単一候補生成の場合は他の候補 (sabbrev 等) を消去して単一確定させる
if ((ADVICE_EXIT==0&&${#COMPREPLY[@]}==1)); then
ble/complete/candidates/clear
[[ $old_cand_count ]] &&
! ble/variable#is-global old_cand_count &&
old_cand_count=0
fi
}
function ble/contrib/integration:zoxide/command.advice {
if [[ ${_ble_attached-} && ${READLINE_MARK+set} ]]; then
ble/bin/stty icanon
ble/function#advice/do
ble/bin/stty -icanon
else
ble/function#advice/do
fi
}
function ble/contrib/integration:zoxide/adjust {
local found=
if ble/is-function _z; then
ble/function#advice around _z ble/contrib/integration:zoxide/completion.advice
found=1
fi
if ble/is-function __zoxide_z_complete; then
ble/function#advice around __zoxide_z_complete ble/contrib/integration:zoxide/completion.advice
found=1
fi
if ble/is-function __zoxide_z; then
ble/function#advice around __zoxide_z ble/contrib/integration:zoxide/command.advice
found=1
fi
if ble/is-function __zoxide_zi; then
ble/function#advice around __zoxide_zi ble/contrib/integration:zoxide/command.advice
found=1
fi
[[ $found ]]
}
if ! ble/contrib/integration:zoxide/adjust; then
ble/bin#has zoxide || return 1
builtin eval -- "$(zoxide init bash)"
ble/contrib/integration:zoxide/adjust
fi