Changes to zsh history behavior and misc commands.
Local (in-memory) history works as before, but only successful commands are commited to storage. Prompt's preexec and precmd hooks no longer corrupt the namespace. Zsh function http-dir now uses vanilla python3 instead of thttpd. Removed aliases/functions: cds, tomp4, swap-files.
This commit is contained in:
parent
eb9fece0a8
commit
dd6ea5923c
2 changed files with 45 additions and 28 deletions
|
@ -131,18 +131,9 @@ wt-list_prefixes () {
|
|||
ls $* $HOME/.local/share/wineprefixes/
|
||||
}
|
||||
|
||||
cds () {
|
||||
cd /mnt/data/$USER/$1
|
||||
}
|
||||
|
||||
http-dir () {
|
||||
echo "Serving $PWD on 0.0.0.0:55555"
|
||||
/usr/sbin/thttpd -T utf-8 -D -d . -p 55555 -l -
|
||||
}
|
||||
|
||||
swap-files () {
|
||||
TMP=.swap-files.tmp
|
||||
mv "$1" "$TMP" && mv "$2" "$1" && mv "$TMP" "$2"
|
||||
python3 -m http.server 55555
|
||||
}
|
||||
|
||||
function die () {
|
||||
|
@ -150,17 +141,6 @@ function die () {
|
|||
exit 1
|
||||
}
|
||||
|
||||
function tomp4 () {
|
||||
__TOMP4_INPUT="${1}"
|
||||
__TOMP4_OUTPUT="${1%%.*}.mp4"
|
||||
|
||||
ffmpeg -i "file:${__TOMP4_INPUT}" -codec:v copy -codec:a copy "${__TOMP4_OUTPUT}"
|
||||
}
|
||||
|
||||
function toTelegram () {
|
||||
over-video --container mp4 --video x264 --video-preset slow --video-quality 22 --no-normalize --audio vorbis --move-source "" +F "scale=1280:trunc(ow/a/2)*2" +A "${@}"
|
||||
}
|
||||
|
||||
function mkvoid () {
|
||||
__MKVOID_TARGET="$1"
|
||||
__MKVOID_PATH="${__MKVOID_TARGET:P}"
|
||||
|
@ -206,14 +186,51 @@ setopt HIST_VERIFY # Don't execute immediately upon history expans
|
|||
bindkey '\e[A' history-beginning-search-backward # completion from history with Up/Down keys
|
||||
bindkey '\e[B' history-beginning-search-forward #
|
||||
|
||||
# general prompt hooks incl. history management
|
||||
# (only commit successful commands, but cache all)
|
||||
# © http://scarff.id.au/blog/2019/zsh-history-conditional-on-command-success/
|
||||
function zshaddhistory() {
|
||||
## called before a history line is saved. See zshmisc(1).
|
||||
|
||||
# Prevent the command from being written to history before it's
|
||||
# executed; save it to LASTHIST instead. Write it to history
|
||||
# in precmd.
|
||||
LASTHIST=$1
|
||||
# Return value 2: "... the history line will be saved on the internal
|
||||
# history list, but not written to the history file".
|
||||
return 2
|
||||
}
|
||||
|
||||
function precmd() {
|
||||
## zsh hook called before the prompt is printed. See zshmisc(1).
|
||||
|
||||
# Write the last command if successful, using the history buffered by
|
||||
# zshaddhistory().
|
||||
if [[ $? == 0 && -n $LASTHIST && -n $HISTFILE ]] ; then
|
||||
print -sr -- ${=${LASTHIST%%'\n'}}
|
||||
fi
|
||||
|
||||
# over-prompt tie in
|
||||
if [[ ! -v OVER_PROMPT_DISABLED ]]; then
|
||||
__over_prompt_precmd || export OVER_PROMPT_DISABLED=1
|
||||
fi
|
||||
}
|
||||
|
||||
function preexec () {
|
||||
if [[ ! -v OVER_PROMPT_DISABLED ]]; then
|
||||
__over_prompt_preexec || export OVER_PROMPT_DISABLED=1
|
||||
fi
|
||||
}
|
||||
|
||||
# general settings
|
||||
setopt EXTENDED_GLOB
|
||||
unsetopt NO_CLOBBER # prevents cat < file > file
|
||||
unsetopt NO_CLOBBER # prevents cat < file > file but gets in the way
|
||||
unsetopt CORRECTALL # hell no
|
||||
setopt NO_BEEP # hell no
|
||||
unsetopt equals # allows me to use strings like =this without escaping
|
||||
export ZLE_REMOVE_SUFFIX_CHARS=$' \t\n;&' # don't remove these chars after completion
|
||||
|
||||
# File completion
|
||||
export ZLE_REMOVE_SUFFIX_CHARS=$' \t\n;&' # don't remove these chars after completion
|
||||
setopt AUTOLIST
|
||||
setopt NO_LIST_AMBIGUOUS # list files immediately
|
||||
setopt LIST_PACKED
|
||||
|
|
|
@ -6,21 +6,21 @@ if [[ -a "$OVER_PROMPT_CFG" ]]; then
|
|||
source "$OVER_PROMPT_CFG"
|
||||
fi
|
||||
|
||||
function set_title {
|
||||
function __over_prompt_set_title {
|
||||
if [[ ${TERM} =~ "screen" ]]; then
|
||||
print -Pn "\033k\033${@}\033\134"
|
||||
fi
|
||||
}
|
||||
|
||||
function preexec {
|
||||
function __over_prompt_preexec {
|
||||
local -a cmd
|
||||
cmd=(${(z)1})
|
||||
|
||||
set_title "${USER}: ${PWD} -> ${cmd}"
|
||||
__over_prompt_set_title "${USER}: ${PWD} -> ${cmd}"
|
||||
}
|
||||
|
||||
function precmd {
|
||||
set_title "${USER}: ${PWD}"
|
||||
function __over_prompt_precmd {
|
||||
__over_prompt_set_title "${USER}: ${PWD}"
|
||||
python3 /usr/share/over-env/prompt.py "${COLUMNS}" "${PWD}" "${OVER_PROMPT_LAST_REFRESH}" "${OVER_PROMPT_SYSLOAD_WARN:=1.25}" "${OVER_PROMPT_SYSLOAD_YELL:=3.0}" "${OVER_PROMPT_FREESPACE_WARN:=0.15}" "${OVER_PROMPT_FREESPACE_YELL:=0.05}"
|
||||
PS1="$(print "%(?.%{\e[1;36m%}.%{\e[1;31m%}%?%{\e[0m%}:%{\e[1;31m%})%(\!.#.$)%{\e[0m%} ")"
|
||||
OVER_PROMPT_LAST_REFRESH=$(date +%s)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue