diff options
author | dakkar <dakkar@thenautilus.net> | 2015-06-24 17:26:19 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2015-06-24 17:26:19 +0100 |
commit | 12e3a710ff4cc9435cc2b984d5a453062b501a79 (patch) | |
tree | 8fb0cd5d450ffb21323d8871cdd95f1e98232b11 /bin/set-screen | |
download | misc-scripts-12e3a710ff4cc9435cc2b984d5a453062b501a79.tar.gz misc-scripts-12e3a710ff4cc9435cc2b984d5a453062b501a79.tar.bz2 misc-scripts-12e3a710ff4cc9435cc2b984d5a453062b501a79.zip |
first few scripts
Diffstat (limited to 'bin/set-screen')
-rwxr-xr-x | bin/set-screen | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/bin/set-screen b/bin/set-screen new file mode 100755 index 0000000..49556e2 --- /dev/null +++ b/bin/set-screen @@ -0,0 +1,58 @@ +#!/bin/bash + +CONFIG_DIR="${HOME}/.config/set-screen" + +function get_display_state_hash() { + local hash etc + read hash etc < <( + for i in /sys/class/drm/card*/card*-*; do + echo $i + cat $i/status + cat $i/edid + done | sha1sum -b) + echo "$hash" +} + +function display_state_dir() { + local hash + hash="$(get_display_state_hash)" + echo "${CONFIG_DIR}/$hash" +} + +function make_display_state_dir() { + local dir + dir="$(display_state_dir)" + mkdir -p "$dir" + echo "Created $dir" +} + +function run_display_state_commands() { + local dir + dir="$(display_state_dir)" + + if [[ -x "${dir}/command" ]]; then + "${dir}/command" + if [[ -x "${CONFIG_DIR}/post-command" ]]; then + "${CONFIG_DIR}/post-command" + fi + fi +} + +function print_usage() { + cat <<EOF +$0 -- re-configure screens + +Usage: + $0 make create directory for current state + $0 set execute 'command' script in directory for current state + $0 same as 'set' + $0 help show this text +EOF +} + +case "$1" in + 'make') make_display_state_dir ;; + '' | 'set') run_display_state_commands ;; + 'help' | '--help' ) print_usage ; exit 0 ;; + *) >&2 print_usage; exit 1 ;; +esac |