sway-stickynotes/sway_stickynotes

48 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

2021-02-21 16:15:25 +00:00
#!/bin/bash
NOTESDIR=~/.config/sway_stickynotes
WORKSPACE=`swaymsg -t get_workspaces -p | grep \(focused\) | cut -f2 -d " "`
function print_usage {
echo "Usage: $0 CMD [VAL]"
echo " CMD ... command: get / set / ask"
echo " get ... returns the current value"
echo " set ... set a new value"
echo " ask ... show a dialog to update the current value"
echo " VAL ... value set when CMD == 'set'"
}
function show_dialog {
CMD=$0
TEMPFILE=~/.config/sway_stickynotes/note
mkdir -p `dirname $TEMPFILE`
$CMD get > $TEMPFILE
dialog --inputbox "Updated stickynote:" 10 30 "`cat $TEMPFILE`" 2> $TEMPFILE
VAL=`cat $TEMPFILE`
$CMD set "$VAL"
}
mkdir -p $NOTESDIR
if [ $1 == "-h" ] || [ $1 == "--help" ]; then
print_usage
exit 0
elif [[ $1 == "get" ]]; then
VAL=`cat $NOTESDIR/$WORKSPACE 2>/dev/null`
echo $VAL
exit 0
elif [[ $1 == "set" ]]; then
shift 1
echo "$@" > $NOTESDIR/$WORKSPACE
exit 0
elif [ $1 == "ask" ]; then
show_dialog
else
print_usage
exit 1
fi