Git Repos / dotfiles / bin / hc_notify.sh
Last update to this file was on 2024-01-02 at 05:12.
Show hc_notify.sh
#!/bin/sh
#
# Copyright (c) 2015-2021 Cameron Vanderzanden. Available under the
# terms of the 2-clause BSD license. Please see the file "LICENSE" in
# the root dir of this repository for more information.
#
#- hc_notify.sh 2015/01/06 cev, last updated 2021/12/07.
## Usage: hc_notify.sh [-hV] [-t timeout] [-u urgency] command <args ...>
##
## Execute herbstclient(1) command and signal the user via dbus
## notification. Valid commands are: close, cycle_layout, floating,
## fullscreen, move_index, pseudotile, remove, split, use_index.
##
## -h Show help options.
## -t Notification timeout (notify-send -t)
## -u Notification urgency (notify-send -u)
## -V Print version info.
##
#
# Simple wrapper script around herbstclient(1). Executes hc command,
# then notifies the user of the action taken using dbus / notify-send.
#
# This could use some updating.
[ -x $HOME/.local/bin/cev_print.sh ] && . $HOME/.local/bin/cev_print.sh
self="${0##*'/'}"
timeout=1000
urgency="low"
name="herbstluftwm"
die_invalidcommand() {
print_self error
printf "%binvalid command %b%s%b\n" "$_norm" "$_error" "$1" "$_clear" >&2
exit 1
}
# simple helper functions
hc() { herbstclient "$@"; }
focuswinid() { hc attr clients.focus.winid; }
taglayout() { hc layout | grep FOC | cut -d' ' -f 4 | cut -d':' -f 1; }
tagname() { hc attr tags.focus.name; }
isfloating() { hc floating status; }
# parse -options
while getopts "ht:u:V?" option; do
case $option in
h) print_help && exit ;;
t) timeout="$OPTARG" ;;
u) urgency="$OPTARG" ;;
V) print_version && exit ;;
"?") print_help && exit ;;
esac
shift $((OPTIND - 1))
done
# shim for 'herbstclient' commands.
case $1 in
clipfix)
xclip -o -selection primary | xclip -i -selection clip-board
name="clipfix"
msg="primary to clipboard"
;;
close) msg="winid $(focuswinid)" && hc close ;;
cycle_layout) shift && hc cycle_layout $@ && msg="layout: $(taglayout)" ;;
floating) shift && hc floating $@ && msg="floating: $(isfloating)" ;;
fullscreen|pseudotile)
hc "$@"
status="$(hc attr clients.focus.$1)"
if [ -z "$status" ]; then exit 0; fi
msg="$1: $status"
;;
move_index) shift && msg="moved $(focuswinid)" && hc move_index $@ ;;
remove) shift && hc remove && msg="frame removed" ;;
split) shift && hc split $@ && msg="split: $@" ;;
use_index) shift && hc use_index $@ && msg="tag: $(tagname)" ;;
*) die_invalidcommand "$1" ;;
esac
# send notification
notify-send -t "$timeout" -u "$urgency" -a "$name" "$msg"
Return to the top of this page or return to the overview of this repo.
Log hc_notify.sh
Date | Commit Message | Author | + | - |
---|---|---|---|---|
2024-01-02 | Change from FreeBSD to Linux, other minor changes | cev | +1 | -1 |
2021-12-13 | Expanded redshift background.sh, misc. changes | cev | +1 | -1 |
2021-12-08 | Initial commit. Dotfiles, scripts, basic Makefile. | cev | +81 |
Return to the top of this page or return to the overview of this repo.