87 lines
1.9 KiB
Bash
87 lines
1.9 KiB
Bash
#!/bin/zsh
|
|
|
|
function venv_prompt() {
|
|
[[ -n ${VIRTUAL_ENV} ]] || return
|
|
echo -e "%F{yellow}%f ${VIRTUAL_ENV:t:gs/%/%%}"
|
|
}
|
|
|
|
function write_title_wd() {
|
|
echo -ne "\033]0;$(print -P "%n@%m [%3~]")\007"
|
|
}
|
|
|
|
function reset_beam() {
|
|
echo -ne '\e[5 q'
|
|
}
|
|
|
|
function lfwrap() {
|
|
LF_DIRFILE="$(mktemp -u)"
|
|
|
|
env lfX -last-dir-path="$LF_DIRFILE" \
|
|
-command "set promptfmt \"$(${HOME}/.local/libexec/lf_prompt)\""
|
|
|
|
dir="$(cat "$LF_DIRFILE")"
|
|
rm "$LF_DIRFILE" &>/dev/null
|
|
|
|
if [ -d "$dir" ]; then
|
|
if [ "$dir" != "$(pwd)" ]; then
|
|
cd "$dir"
|
|
fi
|
|
fi
|
|
|
|
zle reset-prompt
|
|
zle redisplay
|
|
write_title_wd
|
|
reset_beam
|
|
}
|
|
|
|
zle -N lfwrap
|
|
|
|
# Cursor Shape
|
|
function zle-keymap-select() {
|
|
case $KEYMAP in
|
|
vicmd) echo -ne '\e[1 q';; # block
|
|
viins|main) echo -ne '\e[5 q';; # beam
|
|
esac
|
|
}
|
|
zle -N zle-keymap-select
|
|
zle-line-init() {
|
|
zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
|
|
echo -ne "\e[5 q"
|
|
}
|
|
zle -N zle-line-init
|
|
|
|
# CMDLine Edit
|
|
zle -N edit-command-line
|
|
|
|
# Lazygit
|
|
function lg() {
|
|
[ ! -d "$(pwd)/.git" ] && [[ $(read -erk "?Not in a git repository. Create a new git repository? (y/n): ") =~ ^[Yy]$ ]] && git init
|
|
[ -d "$(pwd)/.git" ] && lazygit -p "$(pwd)"
|
|
zle reset-prompt
|
|
}
|
|
zle -N lg
|
|
|
|
# Useful functions for usage in the shell
|
|
function xsi() {
|
|
xpkg -a | \
|
|
fzf -q ${1:-""} -m --preview \
|
|
"xq {1} | \grep -e pkgver -e license -e short_desc -e installed_size -e maintainer -e repository -e homepage" \
|
|
--preview-window=right:66%:wrap | xargs -ro xi
|
|
}
|
|
|
|
function ntfy() {
|
|
"$@" && { notify-send "$1 completed successfully"; return; }
|
|
notify-send -u critical "$1 failed! " "exited with code: $?"
|
|
}
|
|
|
|
function togglefg () {
|
|
zle push-input -w
|
|
BUFFER="fg"
|
|
zle accept-line -w
|
|
}
|
|
zle -N togglefg
|
|
|
|
function whed() {
|
|
[ -e "$1" ] && $EDITOR $(which "$1")
|
|
}
|