diff options
| author | srdusr <trevorgray@srdusr.com> | 2022-12-17 20:10:25 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2022-12-17 20:10:25 +0200 |
| commit | 1cf461f794f7d863a5f949c12dd1e3f8ff707e0e (patch) | |
| tree | 4c09048b6cf4d8b62c886db37aad60de8b1bd59a /.local/bin/scripts/opacity-change.sh | |
| parent | 9f6edf8d5ca151e02e760a96d763bd4019832072 (diff) | |
| parent | a035fc7259fb7a8959d3fada42a426f4289e3619 (diff) | |
| download | dotfiles-1cf461f794f7d863a5f949c12dd1e3f8ff707e0e.tar.gz dotfiles-1cf461f794f7d863a5f949c12dd1e3f8ff707e0e.zip | |
Add '.local/bin/scripts/' from commit 'f797a45b381554f5e34ccaa50716b8bf83219732'
git-subtree-dir: .local/bin/scripts
git-subtree-mainline: ea1c34a7c1fe39421f991ee3607b3c1ddc08eb31
git-subtree-split: f797a45b381554f5e34ccaa50716b8bf83219732
Diffstat (limited to '.local/bin/scripts/opacity-change.sh')
| -rwxr-xr-x | .local/bin/scripts/opacity-change.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/.local/bin/scripts/opacity-change.sh b/.local/bin/scripts/opacity-change.sh new file mode 100755 index 0000000..b509936 --- /dev/null +++ b/.local/bin/scripts/opacity-change.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -eu +[[ -n ${DEBUG:-} ]] && set -x + +#### Example alacritty.yml usage +#key_bindings: +# - { key: N, mods: Control|Shift, action: SpawnNewInstance } +# - { key: O, mods: Control|Shift, command: { program: "opacity-change.sh", args: ["-"] } } +# - { key: P, mods: Control|Shift, command: { program: "opacity-change.sh", args: ["+"] } } + + +operation="${1:-}${2:-}" # Arg #1 & #2 (in case the user misinterpreted a space in the usage), Default '' +step="${operation:1}" # Substring from char index 1 +step="${step:-1}" # Default '1' +operation="${operation:0:1}" # Substring from char index 0 length of 1 +config_file="$HOME/.config/alacritty/alacritty.yml" +config_field="opacity" +tmp_file="/tmp/$(basename $config_file).$(date +%s)" +current_value=$(sed 's/#.*//g; /\b'"$config_field"':/!d; s/.*: \?//' < "$config_file") + +case $operation in +"-") + verb="Decreasing" ;; +"+") + verb="Increasing" ;; +*) + echo "Usage: ${BASH_SOURCE[0]} (-|+)[int]"; exit 255 ;; +esac + +new_value="$(awk '{n=$1+$2/10; print (n<0 ? 0 : n>1 ? 1 : n)}' <<<"$current_value $operation$step")" +echo "$verb $config_field from $current_value to $new_value" >&2 +cp "$config_file" "$tmp_file" +sed "s/\b$config_field:.*/$config_field: $new_value/" "$tmp_file" > "$config_file" + |
