mirror of
https://codeberg.org/frosty/dotfiles.git
synced 2024-09-19 11:47:09 -04:00
(bin): name screenlayout set script and update reference
This commit is contained in:
parent
484bfb18c8
commit
0503ab5fa1
|
@ -1,89 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
err() {
|
|
||||||
echo "$1" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
die() {
|
|
||||||
err "${0##*/}: $1"
|
|
||||||
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
if [ -n "$1" ]; then
|
|
||||||
err "${0##*/}: $1"
|
|
||||||
err
|
|
||||||
fi
|
|
||||||
|
|
||||||
err "usage: ${0##*/} [-hqrde] SCRIPT"
|
|
||||||
err
|
|
||||||
err " -h show this message and exit"
|
|
||||||
err " -q suppress output and notifications"
|
|
||||||
err " -r restore the previous script as your screen layout"
|
|
||||||
err " -d reset screen layout to X default"
|
|
||||||
err " -e edit previous screen layout script in your EDITOR"
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
restore() {
|
|
||||||
[ -f "$XDG_DATA_HOME/screenlayout" ] || die "previous script not found"
|
|
||||||
|
|
||||||
. "$XDG_DATA_HOME/screenlayout"
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
default() {
|
|
||||||
xrandr --auto
|
|
||||||
|
|
||||||
[ -z "$QUIET" ] && notify-send -u low "System" "Screen layout set to default."
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
edit() {
|
|
||||||
[ -z "$EDITOR" ] && die "\$EDITOR is not set"
|
|
||||||
[ -f "$XDG_DATA_HOME/screenlayout" ] || die "previous script not found"
|
|
||||||
|
|
||||||
$EDITOR "$XDG_DATA_HOME/screenlayout"
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
while getopts ":hqrde" opt; do
|
|
||||||
case $opt in
|
|
||||||
h) usage ;;
|
|
||||||
q) QUIET=1 ;;
|
|
||||||
r) restore ;;
|
|
||||||
d) default ;;
|
|
||||||
e) edit ;;
|
|
||||||
\?) usage "invalid option -- '$OPTARG'" ;;
|
|
||||||
:) usage "option requires an argument -- '$OPTARG'" ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
shift $((OPTIND - 1))
|
|
||||||
|
|
||||||
if [ "$1" = "-" ]; then
|
|
||||||
while IFS= read -r line; do
|
|
||||||
script="$line"
|
|
||||||
done
|
|
||||||
else
|
|
||||||
script="$1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
[ -n "$script" ] || usage "SCRIPT was not provided"
|
|
||||||
[ -d "$script" ] && die "$script: is a directory"
|
|
||||||
[ -f "$script" ] || die "$script: no such file"
|
|
||||||
|
|
||||||
case "$(file -b --mime-type "$script")" in
|
|
||||||
text/x-shellscript) ;;
|
|
||||||
*) die "$script: unsupported file type" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
ln -sf "$script" "$XDG_DATA_HOME/screenlayout"
|
|
||||||
. "$XDG_DATA_HOME/screenlayout"
|
|
||||||
|
|
||||||
[ -z "$QUIET" ] && notify-send -u low "System" "Screen layout set to <b>${script##*/}</b>."
|
|
24
.local/bin/screenlayout-set
Executable file
24
.local/bin/screenlayout-set
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die() {
|
||||||
|
printf '%s: %s\n' "${0##*/}" "$1" >&2
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$1" = "-" ]; then
|
||||||
|
while IFS= read -r line; do
|
||||||
|
input="$line"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
input="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -f "$input" ] || die "$input: no such file"
|
||||||
|
case "$input" in
|
||||||
|
/*) ;;
|
||||||
|
*) die "$input: not an absolute path" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
ln -sf "$input" "$XDG_DATA_HOME/screenlayout"
|
||||||
|
. "$XDG_DATA_HOME/screenlayout"
|
|
@ -1,3 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
find "$HOME/.local/bin/screenlayouts" -type f | rofi -dmenu -p screenlayout | screenlayout -
|
selected=$(find "$HOME/.local/bin/screenlayouts" -type f | dmenu -p "screenlayout")
|
||||||
|
printf '%s\n' "$selected" | screenlayout-set -
|
||||||
|
|
Loading…
Reference in a new issue