mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
Improve bash/zsh/terminal consistency
This commit is contained in:
parent
bb8b9420d6
commit
b780b2ce34
9 changed files with 160 additions and 50 deletions
20
zsh/history
20
zsh/history
|
|
@ -1,13 +1,29 @@
|
|||
# ignore sequential duplicates
|
||||
setopt hist_ignore_dups
|
||||
|
||||
# ignore space-started
|
||||
setopt hist_ignore_space
|
||||
setopt hist_reduce_blanks
|
||||
|
||||
# append on exit
|
||||
setopt append_history
|
||||
|
||||
# perform history expansion
|
||||
setopt hist_verify
|
||||
|
||||
# do not load from persistence on every invocation
|
||||
unsetopt share_history
|
||||
|
||||
HISTSIZE=100000
|
||||
SAVEHIST=100000
|
||||
# more! (live)
|
||||
export HISTSIZE=100000
|
||||
|
||||
# all! (persisted)
|
||||
export SAVEHIST=1000000
|
||||
|
||||
# share with bash
|
||||
export HISTFILE=~/.history
|
||||
|
||||
# ignore repeated, space-started, and casual commands
|
||||
HISTORY_IGNORE="(^ +|ls|bg|fg|pwd|exit|cd ..)"
|
||||
|
||||
# vim: ft=zsh
|
||||
|
|
|
|||
26
zsh/prompt
26
zsh/prompt
|
|
@ -184,6 +184,7 @@ set_prompt() {
|
|||
[[ -n "${IN_NIX_SHELL}" ]] && buffer="${buffer} %F{yellow}nix"
|
||||
|
||||
buffer="${buffer}%f> "
|
||||
|
||||
PROMPT="${buffer}"
|
||||
|
||||
local rbuffer=""
|
||||
|
|
@ -203,4 +204,29 @@ set_prompt() {
|
|||
fi
|
||||
}
|
||||
|
||||
mark_prompt() {
|
||||
local mark_a=$'%{\e]133;A\a%}'
|
||||
local mark_b=$'%{\e]133;B\a%}'
|
||||
|
||||
PROMPT="${mark_a}${PROMPT}${mark_b}"
|
||||
}
|
||||
|
||||
mark_command_exec() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
local mark_c="\e]133;C\a"
|
||||
printf "${mark_c}" "${command}"
|
||||
else
|
||||
local command="${1:-}"
|
||||
local mark_c="\e]133;C;cmdline=%q\a"
|
||||
printf "${mark_c}" "${command}"
|
||||
fi
|
||||
}
|
||||
|
||||
mark_command_exit() {
|
||||
local rc="${1:-}"
|
||||
local mark_d="\e]133;D${rc};\a"
|
||||
|
||||
printf "${mark_d}"
|
||||
}
|
||||
|
||||
# vim: ft=zsh
|
||||
|
|
|
|||
5
zsh/rc
5
zsh/rc
|
|
@ -14,7 +14,6 @@ source $DOTFILES_ZSH_DIR/prompt
|
|||
source $DOTFILES_ZSH_DIR/fzf
|
||||
source $DOTFILES_SHELL_DIR/go
|
||||
source $DOTFILES_SHELL_DIR/direnv
|
||||
source $DOTFILES_ZSH_DIR/kitty
|
||||
|
||||
set -o ignoreeof
|
||||
unsetopt BEEP
|
||||
|
|
@ -30,6 +29,8 @@ zmodload zsh/datetime
|
|||
precmd() {
|
||||
CMD_RC=$?
|
||||
|
||||
mark_command_exit "${CMD_RC}"
|
||||
|
||||
if [[ -n ${CMD_START} ]]; then
|
||||
CMD_END="${EPOCHREALTIME}"
|
||||
CMD_DURATION=$(( ${CMD_END} - ${CMD_START} ))
|
||||
|
|
@ -41,11 +42,13 @@ precmd() {
|
|||
psvar=()
|
||||
set_prompt
|
||||
set_term_title
|
||||
mark_prompt
|
||||
}
|
||||
|
||||
preexec() {
|
||||
set_term_title
|
||||
CMD_START="${EPOCHREALTIME}"
|
||||
mark_command_exec "$1"
|
||||
}
|
||||
|
||||
chpwd() {
|
||||
|
|
|
|||
|
|
@ -1,28 +1,37 @@
|
|||
# Tell Apple Terminal about the working directory at each prompt.
|
||||
if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
|
||||
update_terminal_cwd() {
|
||||
# Identify the directory using a "file:" scheme URL,
|
||||
# including the host name to disambiguate local vs.
|
||||
# remote connections. Percent-escape spaces.
|
||||
local SEARCH=' '
|
||||
local REPLACE='%20'
|
||||
local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
|
||||
printf '\e]7;%s\a' "$PWD_URL"
|
||||
}
|
||||
else
|
||||
update_terminal_cwd() { :; }
|
||||
fi
|
||||
|
||||
# Set terminal title
|
||||
set_term_title() {
|
||||
[[ -o interactive ]] || return
|
||||
# Bubble information up to the terminal
|
||||
case $TERM_PROGRAM in
|
||||
Apple_Terminal)
|
||||
local SEARCH=' '
|
||||
local REPLACE='%20'
|
||||
local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
|
||||
printf '\e]7;%s\a' "$PWD_URL"
|
||||
;;
|
||||
*)
|
||||
# NOOP
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -n "${SSH_CLIENT}" ]]; then
|
||||
local title="$USER@${HOSTNAME%%.*}:${PWD/#$HOME/~}"
|
||||
else
|
||||
local title="${PWD/#$HOME/~}"
|
||||
fi
|
||||
|
||||
update_terminal_cwd
|
||||
|
||||
case $TERM in
|
||||
screen*)
|
||||
screen*|xterm*|rxvt*|alacritty)
|
||||
#print -Pn "\ek%n@%m: %~\e\\" #breaks tmux
|
||||
print -Pn "\e]2;%n@%m: %~\a"
|
||||
;;
|
||||
xterm*|*rxvt*)
|
||||
print -Pn "\e]2;%n@%m: %~\a"
|
||||
printf "\e]2;%s\a" "${title}"
|
||||
;;
|
||||
*)
|
||||
# NOOP
|
||||
: # NOOP
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue