feat(shell): major refactor around history and completion setup

Biggest change is embracing fzf for all shell completion. This includes
using tmux popup windows to effectively render completions as floating
popups with fuzzy matching via fzf.

Shell history has also been improved, with appending each command to the
history file one by one, rather than only at end of a shell session when
the shell exists. This should ensure I don't have any more lost commands
cause the shell didn't exit cleanly.
This commit is contained in:
2024-05-19 00:08:04 +01:00
parent 3a6e6a5256
commit 98f0b2ec66
5 changed files with 155 additions and 54 deletions

View File

@@ -1,18 +0,0 @@
#
# fzf
#
export FZF_CTRL_T_OPTS="--preview='less {}'"
export FZF_DEFAULT_OPTS="--bind=ctrl-k:kill-line --border=none --tabstop=4"
export FZF_TMUX=0
export FZF_TMUX_HEIGHT=100%
# Install fzf binary from latest GitHub Release.
zinit light-mode wait lucid from'gh-r' as'program' pick'fzf' \
for @junegunn/fzf
# Install fzf-tmux command and zsh plugins from default branch on GitHub.
zinit light-mode wait lucid from'gh' as'program' pick'bin/fzf-tmux' \
multisrc'shell/{completion,key-bindings}.zsh' \
id-as'junegunn/fzf-extras' \
for @junegunn/fzf

View File

@@ -2,6 +2,13 @@
# Ruby environment setup.
#
# ==============================================================================
# bundler
# ==============================================================================
# Enable Ruby Bundler plugin from oh-my-zsh.
zinit for @OMZ::plugins/bundler
# ==============================================================================
# aliases
# ==============================================================================

View File

@@ -1,5 +1,5 @@
#
# Interactive Utility Functions
# zshrc helper functions
#
# Helpers designed for use during setup of interactive shell environments
# (~/.zshrc ).
@@ -36,32 +36,32 @@
setup-completions() {
local cmd="$1"
local source="$2"
local setup_cmd="$3"
shift 3
shift 2
local script="$@"
local target_dir="${ZSH_COMPLETIONS:-$HOME/.zsh/completions}"
local target_file="${target_dir}/_${cmd}"
if [[ -z "$cmd" || -z "$source" || -z "$script" ]]; then
echo "setup-completions: Missing required arguments." >&2
return 1
fi
if [[ -z "$(command -v "$cmd")" ]]; then
echo "setup-completions: Command not found: $cmd" >&2
return 1
fi
if [[ -z "$(command -v "$setup_cmd")" ]]; then
echo "setup-completions: Command not found: $setup_cmd" >&2
return 1
fi
if [[ -z "$cmd" || -z "$source" || -z "$setup_cmd" ]]; then
echo "setup-completions: Missing required arguments." >&2
if [[ -z "$source" ]]; then
echo "setup-completions: Source file not found: $source" >&2
return 1
fi
# Check if the target completion file needs to be updated
if [[ ! -f "$target_file" || "$source" -nt "$target_file" ]]; then
echo "setup-completions: Setting up completion for $cmd --> $target_file" >&2
echo "setup-completions: Setting up completion for $cmd: $script" >&2
mkdir -p "$target_dir"
"$setup_cmd" "$@" >| "$target_file"
eval "$script" >| "$target_file"
chmod +x "$target_file"
# Only run compinit if not already loaded