This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/env/sh/shell_funcs

85 lines
1.5 KiB
Bash

#!/usr/bin/env bash
calc() {
python -c "print($@)"
}
export -f calc
stopbar() {
if [[ -f "$BAR_PID_FILE" ]]; then
echo
kill -SIGINT $(cat "$BAR_PID_FILE")
rm -f "$BAR_PID_FILE"
else
echo "Bar is not running."
fi
}
export -f stopbar
# wm aliases
startbar() {
if [[ -f "$BAR_PID_FILE" ]]; then
stopbar
fi
"$BAR_PATH/start.bash" &
BAR_PID=$!
echo "$BAR_PID" > "$BAR_PID_FILE"
kill -CONT "$BAR_PID"
# bg
# disown
# lower the bar's layer so fullscreen windows cover it
wid=$(xdo id -a "$BAR_WID")
tries=20
while [ -z "$wid" -a "$tries" -gt 0 ]; do
sleep 0.1
wid=$(xdo id -a "$BAR_WID")
tries=$((tries - 1))
echo "WID $wid"
done
[ -n "$wid" ] && xdo above -t "$(xdo id -N Bspwm -n root | sort | head -n 1)" "$wid"
fg
}
export -f startbar
# save the current directory for later retrieval
scwd() {
addon=""
if [[ -n $1 ]]; then
addon="-$1"
fi
echo "$PWD" > "$DOTFILES_PATH/env/sh/cwd$addon.tmp"
}
export -f scwd
bind '"\C-s"':"\"scwd\C-m\""
# go to the saved current directory
gcwd() {
addon=""
if [[ -n $1 ]]; then
addon="-$1"
fi
cd $(cat "$DOTFILES_PATH/env/sh/cwd$addon.tmp")
}
export -f gcwd
bind '"\C-g"':"\"gcwd\C-m\""
# man pages with vim
vman() {
if command -v nvim >/dev/null 2>&1; then
nvim -c "SuperMan $*"
else
vim -c "SuperMan $*"
fi
if [ "$?" != "0" ]; then
echo "No manual entry for $*"
fi
}
alias _man="\\man"
alias man="vman"
# close a terminal with Ctrl-Shift-D (in theory)
bind '"\C-D"':"\"\C-c\C-d\""