mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
Compare commits
No commits in common. "e646389fab846c796e1028ae187e4bb7551896ac" and "d50534572d71195b78f5033c9e589a267c5dc0e5" have entirely different histories.
e646389fab
...
d50534572d
3 changed files with 20 additions and 90 deletions
90
bash/ext
90
bash/ext
|
|
@ -1,106 +1,36 @@
|
||||||
# Make Bash more like Zsh
|
# Make Bash more like Zsh
|
||||||
|
|
||||||
|
|
||||||
## Hooks
|
# Hooks
|
||||||
# https://zsh.sourceforge.io/Doc/Release/Functions.html#Hook-Functions
|
# derived from http://glyf.livejournal.com/63106.html
|
||||||
|
|
||||||
# TODO: support precmd_functions and chpwd_functions arrays
|
# TODO: support precmd_functions and chpwd_functions arrays
|
||||||
|
|
||||||
### Defaults: NOOPs
|
# default: NOOPs
|
||||||
|
|
||||||
function preexec { :; }
|
function preexec { :; }
|
||||||
|
|
||||||
function precmd { :; }
|
function precmd { :; }
|
||||||
|
|
||||||
function chpwd { :; }
|
function chpwd { :; }
|
||||||
|
|
||||||
### Implementations
|
|
||||||
|
|
||||||
# Alternative cd function that calls chpwd afterwards builtin cd
|
|
||||||
#
|
|
||||||
# zsh: Executed whenever the current working directory is changed.
|
|
||||||
__cd_invoke_chpwd() {
|
__cd_invoke_chpwd() {
|
||||||
builtin cd "$@"
|
builtin cd "$@"
|
||||||
|
|
||||||
chpwd
|
chpwd
|
||||||
|
|
||||||
# TODO: chpwd_functions array
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# zsh: Executed before each prompt. Note that precommand functions are not
|
__preexec_invoke_exec () {
|
||||||
# re-executed simply because the command line is redrawn, as happens, for
|
|
||||||
# example, when a notification about an exiting job is displayed.
|
|
||||||
__prompt_command_invoke_precmd() {
|
|
||||||
precmd
|
|
||||||
|
|
||||||
# TODO: precmd_functions array
|
|
||||||
}
|
|
||||||
|
|
||||||
# to properly trigger only before command exec this must be the last prompt command
|
|
||||||
__prompt_command_hook_preexec() {
|
|
||||||
trap '__debug_invoke_preexec' DEBUG
|
|
||||||
}
|
|
||||||
|
|
||||||
__prompt_command_unhook_preexec() {
|
|
||||||
# Unfortunately there's no way to remove just one trap from a signal
|
|
||||||
trap - DEBUG
|
|
||||||
}
|
|
||||||
|
|
||||||
# zsh: Executed just after a command has been read and is about to be executed. If
|
|
||||||
# the history mechanism is active (regardless of whether the line was discarded
|
|
||||||
# from the history buffer), the string that the user typed is passed as the
|
|
||||||
# first argument, otherwise it is an empty string. The actual command that will
|
|
||||||
# be executed (including expanded aliases) is passed in two different forms:
|
|
||||||
# the second argument is a single-line, size-limited version of the command
|
|
||||||
# (with things like function bodies elided); the third argument contains the
|
|
||||||
# full text that is being executed.
|
|
||||||
__debug_invoke_preexec () {
|
|
||||||
# somehow PROMPT_COMMAND contents seems to be still affected by the
|
|
||||||
# just-removed trap. Ignore ours.
|
|
||||||
[[ "$BASH_COMMAND" == "__prompt_command_unhook_preexec" ]] && return
|
|
||||||
[[ "$BASH_COMMAND" == "__prompt_command_invoke_precmd" ]] && return
|
|
||||||
[[ "$BASH_COMMAND" == "__prompt_command_hook_preexec" ]] && return
|
|
||||||
|
|
||||||
# TODO: not sure this is still necessary
|
|
||||||
[[ -n "$COMP_LINE" ]] && return # completion
|
|
||||||
|
|
||||||
local this_command;
|
local this_command;
|
||||||
|
|
||||||
# TODO: hack: doesn't work when command is not added to history
|
[ -n "$COMP_LINE" ] && return # completion
|
||||||
|
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # precmd
|
||||||
|
|
||||||
this_command=`history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g"`;
|
this_command=`history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g"`;
|
||||||
preexec "$this_command"
|
preexec "$this_command"
|
||||||
}
|
}
|
||||||
|
|
||||||
### Set up the hooks
|
# set up the hooks
|
||||||
|
PROMPT_COMMAND="precmd"
|
||||||
# Define a function to override the cd builtin
|
trap '__preexec_invoke_exec' DEBUG
|
||||||
#
|
|
||||||
# - does not apply to `bash -c 'cd foo`
|
|
||||||
# - does apply to shubshells: `(cd foo)` will call so side effects beware (env
|
|
||||||
# vars are conveniently scoped to subshell)
|
|
||||||
cd() { __cd_invoke_chpwd "$@"; }
|
cd() { __cd_invoke_chpwd "$@"; }
|
||||||
|
|
||||||
# Call on each prompt. This transitively sets preexec to work for each prompt
|
|
||||||
#
|
|
||||||
# PROMPT_COMMAND is evaluated right before PS1 is displayed. This matches zsh
|
|
||||||
# semantics for precmd.
|
|
||||||
#
|
|
||||||
# We forcefully set it instead of taking whatever was set:
|
|
||||||
# - to control order (precmd eval + preexec hooking must be last)
|
|
||||||
# - because of the trap issue
|
|
||||||
PROMPT_COMMAND=(
|
|
||||||
# this also conveniently clears DEBUG traps
|
|
||||||
__prompt_command_unhook_preexec
|
|
||||||
|
|
||||||
# precmd hook processing
|
|
||||||
__prompt_command_invoke_precmd
|
|
||||||
|
|
||||||
# must be last to properly have DEBUG trigger only before command exec
|
|
||||||
__prompt_command_hook_preexec
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
## Other bits
|
|
||||||
|
|
||||||
# clears a line that was not terminated by a LF fixing the dangling prompt
|
# clears a line that was not terminated by a LF fixing the dangling prompt
|
||||||
# issue by marking it with a reversed %, like zsh
|
# issue by marking it with a reversed %, like zsh
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
# if test -n "$KITTY_INSTALLATION_DIR"; then
|
if test -n "$KITTY_INSTALLATION_DIR"; then
|
||||||
# export KITTY_SHELL_INTEGRATION="enabled"
|
export KITTY_SHELL_INTEGRATION="enabled"
|
||||||
# source "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash"
|
source "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash"
|
||||||
# fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
12
zsh/kitty
12
zsh/kitty
|
|
@ -1,6 +1,6 @@
|
||||||
# if test -n "$KITTY_INSTALLATION_DIR"; then
|
if test -n "$KITTY_INSTALLATION_DIR"; then
|
||||||
# export KITTY_SHELL_INTEGRATION="enabled"
|
export KITTY_SHELL_INTEGRATION="enabled"
|
||||||
# autoload -Uz -- "$KITTY_INSTALLATION_DIR"/shell-integration/zsh/kitty-integration
|
autoload -Uz -- "$KITTY_INSTALLATION_DIR"/shell-integration/zsh/kitty-integration
|
||||||
# kitty-integration
|
kitty-integration
|
||||||
# unfunction kitty-integration
|
unfunction kitty-integration
|
||||||
# fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue