dotfiles/zsh/.config/zsh/functions.zsh

60 lines
1.4 KiB
Bash

bt() {
(( ${+commands[bluetoothctl]} )) || return 2
if [[ $1 == on ]]; then
(( ${+commands[connmanctl]} )) \
&& connmanctl enable bluetooth \
|| bluetoothctl power on
elif [[ $1 == off ]]; then
(( ${+commands[connmanctl]} )) \
&& connmanctl disable bluetooth \
|| bluetoothctl power off
else
bluetoothctl "$@"
fi
}
doasedit() {
(( ${+commands[doas]} )) || return 2
[[ $# -eq 0 ]] || return 1
doas -L
doas -u root sh -c \
"cp /etc/doas.conf /tmp/doas.conf \
&& rvim -n /tmp/doas.conf \
&& doas -C /tmp/doas.conf \
&& mv /tmp/doas.conf /etc/doas.conf \
&& echo 'ok' \
|| echo >&2 'error'"
local STATUS=$?
doas -L
return $STATUS
}
get_ip() {
(( ${+commands[curl]} )) || return 2
while [[ $# -gt 0 ]]; do
[[ $1 == --ip ]] \
&& local IP="?ip=$2" && shift \
|| local ARGS+=("$1")
shift
done
eval "curl ${ARGS[@]} -fsSL 'https://ifconfig.co/json$IP' \
$( (( ${+commands[jq]} )) && echo "| jq" )"
}
http() {
(( ${+commands[python]} )) || return 2
eval "python -m http.server 8080 --bind 127.0.0.1 \
$( [[ $# -gt 0 ]] && echo "--directory $1" ) $@"
}
open() {
(( ${+commands[xdg-open]} )) || return 2
nohup xdg-open "$@" &> /dev/null & disown
}