From a4f2b3310c7750d3ae176d2d6b261ec7ea284f52 Mon Sep 17 00:00:00 2001 From: John Mertz Date: Mon, 23 Nov 2020 04:35:26 -0500 Subject: [PATCH] Kernel formatting --- README.md | 118 ++- apply-gruvbox.sh | 1080 +++++++++++----------- audio/noise-cancel.sh | 5 +- i3/detached.sh | 9 +- i3/home.sh | 11 +- i3/i3move.sh | 24 +- i3/work.sh | 11 +- rofi/drun.sh | 4 +- rofi/rofi-openvpn.sh | 30 +- rofi/rofi-power-menu.sh | 36 +- rofi/rofi-send-to-kodi.sh | 3 +- rofi/rofi-ssh-menu.sh | 29 +- rofi/sway-alt-tab.sh | 6 +- send-to-kodi.sh | 58 +- sway/displays.pl | 403 ++++---- sway/gammastep.pl | 33 +- sway/popup-term.pl | 88 +- sway/swayidle.sh | 46 +- sway/swayidlecountdown.sh | 2 +- sway/toggle_outputs.sh | 4 +- thinkpad/blc.pl | 467 +++++----- thinkpad/kbd_backlight.pl | 32 +- thinkpad/user-thinkpad-controls@.service | 4 +- update-firefox.pl | 160 ++-- waybar/waybar-cpu.sh | 4 +- waybar/waybar-disk.sh | 6 +- waybar/waybar-mem.sh | 4 +- waybar/waybar-nmtui.sh | 8 +- 28 files changed, 1451 insertions(+), 1234 deletions(-) diff --git a/README.md b/README.md index 4ad8ae3..4087bf2 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,51 @@ # Simple Scripts + ## Audio **audio/mute.sh** Just a simple script to toggle Alsa mute. ---- - **audio/noise-cancel.sh** Add a noise-cancelled version of existing interfaces to Pulseaudio. ## i3 -I haven't used i3 in earnest for quite some time since moving to Sway, so it is very likely that some of these scripts are broken based on other config changes. +I haven't used i3 in earnest for quite some time since moving to Sway, so it is +very likely that some of these scripts are broken based on other config changes. **i3/i3move.sh** -When any of the Xrandr scripts below is run, it will print it's name to a config file. This script will read that config file and then knows how the outputs are arranged. Once this is known, it allows hotkeys to know which output to move a workspace to. +When any of the Xrandr scripts below is run, it will print it's name to a config +file. This script will read that config file and then knows how the outputs are +arranged. Once this is known, it allows hotkeys to know which output to move a +workspace to. **i3/detached.sh** Xrandr config. Just the laptop display. -**i3/work.sh** +**i3/detached.sh** -Xrandr config. Vertical on the left, horizontal aligned to top of the vertical, and laptop directly below that. Left-to-right order is Vertical-Horizontal-Laptop. +Xrandr config. Just the laptop display. **i3/home.sh** -Xrandr config. Not a layout I currently use. Home is now the "stacked" view from sway/displays. +Xrandr config. Not a layout I currently use. Home is now the "stacked" view from +sway/displays. + +**i3/work.sh** + +Xrandr config. Vertical on the left, horizontal aligned to top of the vertical, +and laptop directly below that. Left-to-right order is +Vertical-Horizontal-Laptop. ## Rofi -[Rofi](https://github.com/davatorium/rofi) is a neat graphical launcher and menu system. I use it for a bunch of stuff to supplement i3 and Sway to fill out same desktop niceties. See configs in 'dotfiles' repository. +[Rofi](https://github.com/davatorium/rofi) is a neat graphical launcher and menu +system. I use it for a bunch of stuff to supplement i3 and Sway to fill out same +desktop niceties. See configs in 'dotfiles' repository. **rofi/drun.sh** @@ -53,7 +65,8 @@ Forward pasted link to ./send-to-kodi.sh. **rofi/rofi-ssh-menu.sh** -Open a terminal to any SSH shortcut machine. (TODO: Integrate with 'sshs' to get machine list from there instead of a static list). +Open a terminal to any SSH shortcut machine. (TODO: Integrate with 'sshs' to get +machine list from there instead of a static list). **rofi/sway-alt-tab.sh** @@ -61,27 +74,40 @@ Show all currently running applications in Sway to locate window. ## Sway -[Sway](https://github.com/swaywm/sway) is an i3-compatible Wayland compositor and tiling window manager. See configs in 'dotfiles' repository. Here are some scripts exclusively for automating or enhancing Sway. +[Sway](https://github.com/swaywm/sway) is an i3-compatible Wayland compositor +and tiling window manager. See configs in 'dotfiles' repository. Here are some +scripts exclusively for automating or enhancing Sway. **sway/displays.pl** -Script to automatically configure wayland outputs using swaymsg. Also forks waybars for each display. Allows custom configurations. No argument will run the last used configuration (~/config/last_display). '-w' will run only waybar without changing displays. +Script to automatically configure wayland outputs using swaymsg. Also forks +waybars for each display. Allows custom configurations. No argument will run the +last used configuration (~/config/last_display). '-w' will run only waybar +without changing displays. **sway/gammastep.pl** -Setup Gammastep based on current location. I don't have geolocation in my laptop, so this requires a URL that returns JSON, including a "lat" and "lon". My URL (restricted to my IPs) returns these as recorded by PhoneTrack on my phone similar to: +Setup Gammastep based on current location. I don't have geolocation in my +laptop, so this requires a URL that returns JSON, including a "lat" and "lon". +My URL (restricted to my IPs) returns these as recorded by PhoneTrack on my +phone similar to: ``` {"lat":"180.12345678","lon":"-180.12345678","timestamp":"1599831660"} ``` -It forks to keep running if terminal is killed to remove the need for nohup. If location fails to be fetched it will try again every 5 seconds. +It forks to keep running if terminal is killed. If location fails to be fetched +it will try again every 5 seconds. **sway/popup-term.pl** -A DIY version of the Tilde terminal. If terminal is not running, it opens on the current display. If it is running but not on current display, it moves to current display. If it is already on current display, it is moved to a hidden display ('grave'). +A DIY version of the Tilde terminal. If terminal is not running, it opens on the +current display. If it is running but not on current dislpay, it moves to +current display. If it is already on current display, it is moved to a hidden +display ('grave'). -Note the relevant settings in dotfiles repository (sway/config) related to the 'grave' workspace, as well as UXTerm which is configured to open floating in the bottom corner. +Note the relevant settings in dotfiles repository (sway/config) related to the +'grave' workspace, as well as UXTerm. ``` for_window [class="UXTerm"] floating enable, resize set height 600px, resize set width 800px, move position 1120px 460px @@ -91,58 +117,69 @@ bindsym $mod+Grave exec /home/jpm/scripts/sway/popup-term.pl bindsym $mod+Shift+Grave workspace grave ``` -Also note that 'grave' has no label in waybar (waybar/config.template) to allow it to be *hidden*. +Also note that 'grave' has no label in waybar (waybar/config.template) to allow +it to be *hidden*. ``` "sway/workspaces": { - "format": "{icon}", + "format": "{icon}", "format-icons": { - "0": "0 \uf073", // Example of workspace with a label - "grave": "", - ... + "0": "0 \uf073", // Example of workspace with a label + "grave": "", + ... ``` **sway/swayidle.sh** Work in progress. These scripts don't currently work the way I like. -Sway has an Idle detection daemon that can flexibly take different actions after certain periods of inactivity as well as prior to sleep and after wake. +Sway has an Idle detection daemon that can flexibly take different actions after +certain periods of inactivity as well as prior to sleep and after wake. -This script is meant to unify all of the actions into one script by accepting an option. +This script is meant to unify all of the actions into one script by accepting an +option. **sway/swayidlecountdown.sh** -Prior to locking, a countdown should be provided. Currently testing how to manage a countdown with Dunst, which doesn't actually support dynamic notifications. - -**sway/toggle_outputs** - -Swap between detached and docked modes using `sway/displays.pl`. Bound to function key for external monitor button. +Prior to locking a countdown should be provided. Currently testing how to manage +a countdown with Dunst, which doesn't actually support dynamic notifications. ## Thinkpad **thinkpad/blc.pl** - -Overly complicated backlight brightness control script. Provides flexible control of backlight so that changes can be easily scripted or called from keyboard shortcuts. --help provides some usage docs. + +Overly complicated backlight brightness control script. Provides flexible +control of backlight so that changes can be easily scripted or called from +keyboard shortcuts. --help provides some usage docs. **thinkpad/kbd_backlight.pl** - -Simple script to cycle keyboard backlight. Gets max brightness, current brightness and then changes then increments the current brightness. Uses mod of max+1 so that it will cycle back around to 0 (disabled) if it is already at max. + +Simple script to cycle keyboard backlight. Gets max brightness, current +brightness and then changes then increments the current brightness. Uses mod of +max+1 so that it will cycle back around to 0 (disabled) if it is already at max. **thinkpad/user-thinkpad-control@.service** - -SystemD unit file used to give ownership of necessary sys files to whichever user it is enabled for `systemctl enable user-thinkpad-control@jpm`. Without this, the user won't be able to write these files and thus cannot set brightness values. + +SystemD unit file used to give ownership of necessary sys files to whichever +user it is enabled for `systemctl enable user-thinkpad-control@jpm`. Without +this, the user won't be able to write these files and thus cannot set brightness +values. ## Waybar -[Waybar](https://github.com/Alexays/Waybar) is a very flexible and customizable taskbar for Sway (and other Wlroots-based wayland compositors). Waybar applets have hover and click functionality and have several scripts related to those. See the .config repository for the actual Waybar and Sway configs. +[Waybar](https://github.com/Alexays/Waybar) is a very flexible and customizable +taskbar for Sway (and other Wlroots-based wayland compositors). Waybar applets +have hover and click functionality and have several scripts related to those. +See the .config repository for the actual Waybar and Sway configs. - **waybar/waybar-cpu.sh** +**waybar/waybar-cpu.sh** Launch htop in floating window (bottom-right). If already running, kill it. **waybar/waybar-disk.sh** -Notification with disk usage summaries. Renders properly with Dunst, but not Mako. +Notification with disk usage summaries. Renders properly with Dunst, but not +Mako. **waybar/waybar-mem.sh** @@ -156,8 +193,13 @@ Launch nmtui in floating window (bottom-right). If already running, kill it. **send-to-kodi.sh** -[This script](https://github.com/allejok96/send-to-kodi) sends a URL or local file to a [Kodi](https://github.com/xbmc) media player. Only modified to have my local media server IP. +[This script](https://github.com/allejok96/send-to-kodi) sends a URL or local +file to a [Kodi](https://github.com/xbmc) media player. Only modified to have my +local media server IP. **apply-gruvbox.sh** -A single theme version of the one provided [here](https://raw.githubusercontent.com/Mayccoll/Gogh). Applies the theme to a variety of terminals. Not really necessary after cloning the 'dotfiles' repository. \ No newline at end of file +A single theme version of the one provided +[here](https://raw.githubusercontent.com/Mayccoll/Gogh). Applies the theme to a +variety of terminals. Not really necessary after cloning the 'dotfiles' +repository. diff --git a/apply-gruvbox.sh b/apply-gruvbox.sh index 6eda344..780a818 100644 --- a/apply-gruvbox.sh +++ b/apply-gruvbox.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -# Single theme copy of apply-colors.sh from: https://raw.githubusercontent.com/Mayccoll/Gogh +# Single theme copy of apply-colors.sh from: +# https://raw.githubusercontent.com/Mayccoll/Gogh # ====================CONFIG THIS =============================== # export COLOR_01="#282828" # HOST @@ -43,30 +44,31 @@ GS="${GS:-$(command -v gsettings | xargs echo)}" # | handled there in case there was en error before this script was called # | ============================================ GLOBAL_VAR_CLEANUP() { - unset PROFILE_NAME - unset PROFILE_SLUG - unset scratchdir - unset TILIX_RES - unset TERMINAL - unset LOOP - unset OPTLENGTH + unset PROFILE_NAME + unset PROFILE_SLUG + unset scratchdir + unset TILIX_RES + unset TERMINAL + unset LOOP + unset OPTLENGTH - for c in $(seq -s " " -w 16); do - unset DEMO_COLOR_${c} - unset COLOR_${c} - done + for c in $(seq -s " " -w 16); do + unset DEMO_COLOR_${c} + unset COLOR_${c} + done - unset BACKGROUND_COLOR - unset FOREGROUND_COLOR - unset CURSOR_COLOR - unset HIGHLIGHT_FG_COLOR - unset HIGHLIGHT_BG_COLOR - unset USE_SYS_TRANSPARENCY - unset PROFILE_NAME + unset BACKGROUND_COLOR + unset FOREGROUND_COLOR + unset CURSOR_COLOR + unset HIGHLIGHT_FG_COLOR + unset HIGHLIGHT_BG_COLOR + unset USE_SYS_TRANSPARENCY + unset PROFILE_NAME } -# Note: Since all scripts gets invoked in a subshell the traps from the parent shell -# will not get inherited. Hence traps defined in gogh.sh and print-themes.sh will still trigger +# Note: Since all scripts gets invoked in a subshell the traps from the parent +# shell will not get inherited. Hence traps defined in gogh.sh and +# print-themes.sh will still trigger trap 'GLOBAL_VAR_CLEANUP; trap - EXIT' EXIT HUP INT QUIT PIPE TERM # | =========================================== @@ -75,67 +77,65 @@ trap 'GLOBAL_VAR_CLEANUP; trap - EXIT' EXIT HUP INT QUIT PIPE TERM # | ============================================ if [[ -z "${TERMINAL:-}" ]]; then - # | =========================================== - # | Check for the terminal name (depening on os) - # | =========================================== - OS="$(uname)" - if [[ "$OS" = "Darwin" ]]; then - TERMINAL=$TERM_PROGRAM - elif [[ "${OS#CYGWIN}" != "${OS}" ]]; then - TERMINAL="mintty" - else - # | =========================================== - # | Depending on how the script was invoked, we need - # | to loop until pid is no longer a subshell - # | =========================================== - pid="$$" - TERMINAL="$(ps -h -o comm -p $pid)" - while [[ "${TERMINAL:(-2)}" == "sh" ]]; do - pid="$(ps -h -o ppid -p $pid)" - TERMINAL="$(ps -h -o comm -p $pid)" - done - fi + # | =========================================== + # | Check for the terminal name (depening on os) + # | =========================================== + OS="$(uname)" + if [[ "$OS" = "Darwin" ]]; then + TERMINAL=$TERM_PROGRAM + elif [[ "${OS#CYGWIN}" != "${OS}" ]]; then + TERMINAL="mintty" + else + # | =========================================== + # | Depending on how the script was invoked, we need + # | to loop until pid is no longer a subshell + # | =========================================== + pid="$$" + TERMINAL="$(ps -h -o comm -p $pid)" + while [[ "${TERMINAL:(-2)}" == "sh" ]]; do + pid="$(ps -h -o ppid -p $pid)" + TERMINAL="$(ps -h -o comm -p $pid)" + done + fi fi case "${TERMINAL}" in - pantheon-terminal|io.elementary.t* ) - if [[ -z "${GS}" ]]; then - printf '\n%s\n' "Error gsettings not found" - printf '%s\n' "sudo apt install dconf?" - printf '%s\n\n' "or export GS=/path/to/gsettings" - exit 1 - fi - ;; - - mintty ) - CFGFILE="${HOME}/.minttyrc" - if [[ ! -f "${CFGFILE}" ]]; then - printf '\n%s\n' "Warning: Couldn't find an existing configuration file, so one will be created for you." - printf '%s\n\n' "Warning: Are you really running Cygwin's mintty?" - touch "${CFGFILE}" - fi - ;; - - guake|tilix|mate-terminal|gnome-terminal* ) - case "${TERMINAL}" in - guake|gnome-terminal* ) - if [[ -z "${DCONF}" ]] && [[ -z "${GCONF}" ]]; then - printf '\n%s\n' "Error gconftool not found!" - printf '%s\n' "sudo apt install gconftool?" - printf '%s\n\n' "or export GCONF=/path/to/gconftool-2/" - exit 1 +pantheon-terminal|io.elementary.t* ) + if [[ -z "${GS}" ]]; then + printf '\n%s\n' "Error gsettings not found" + printf '%s\n' "sudo apt install dconf?" + printf '%s\n\n' "or export GS=/path/to/gsettings" + exit 1 + fi + ;; +mintty ) + CFGFILE="${HOME}/.minttyrc" + if [[ ! -f "${CFGFILE}" ]]; then + printf '\n%s\n' "Warning: Couldn't find an existing configuration file, \ +so one will be created for you." + printf '%s\n\n' "Warning: Are you really running Cygwin's mintty?" + touch "${CFGFILE}" + fi + ;; +guake|tilix|mate-terminal|gnome-terminal* ) + case "${TERMINAL}" in + guake|gnome-terminal* ) + if [[ -z "${DCONF}" ]] && [[ -z "${GCONF}" ]]; then + printf '\n%s\n' "Error gconftool not found!" + printf '%s\n' "sudo apt install gconftool?" + printf '%s\n\n' "or export GCONF=/path/to/gconftool-2/" + exit 1 + fi + ;; + esac + if [[ -z "${DCONF}" ]]; then + printf '\n%s\n' "Error dconf not found" + printf '%s\n' "sudo apt install dconf?" + printf '%s\n\n' "or export DCONF=/path/to/dconf" + exit 1 fi ;; - esac - if [[ -z "${DCONF}" ]]; then - printf '\n%s\n' "Error dconf not found" - printf '%s\n' "sudo apt install dconf?" - printf '%s\n\n' "or export DCONF=/path/to/dconf" - exit 1 - fi - ;; - esac # | =========================================== @@ -143,192 +143,205 @@ esac # | =========================================== gnome_color () { - AA=${1:1:2} - BB=${1:3:2} - CC=${1:5:2} + AA=${1:1:2} + BB=${1:3:2} + CC=${1:5:2} - echo "#${AA}${AA}${BB}${BB}${CC}${CC}" + echo "#${AA}${AA}${BB}${BB}${CC}${CC}" } hexToDec () { - echo "$((16#${1}))" + echo "$((16#${1}))" } hexRGBtoDecRGB () { - R="$(hexToDec "${1:1:2}")" - G="$(hexToDec "${1:3:2}")" - B="$(hexToDec "${1:5:2}")" + R="$(hexToDec "${1:1:2}")" + G="$(hexToDec "${1:3:2}")" + B="$(hexToDec "${1:5:2}")" - echo "${R}" "${G}" "${B}" + echo "${R}" "${G}" "${B}" } convertRGBtoMac () { - local color="${1}" - set -- - set -- $(hexRGBtoDecRGB "${color}") - R=${1}; shift; G=${1}; shift; B=${1}; shift + local color="${1}" + set -- + set -- $(hexRGBtoDecRGB "${color}") + R=${1}; shift; G=${1}; shift; B=${1}; shift - R=$(echo "${R} / 255" | bc -l) - G=$(echo "${G} / 255" | bc -l) - B=$(echo "${B} / 255" | bc -l) + R=$(echo "${R} / 255" | bc -l) + G=$(echo "${G} / 255" | bc -l) + B=$(echo "${B} / 255" | bc -l) - echo "${R}" "${G}" "${B}" + echo "${R}" "${G}" "${B}" } createMinttyEntry () { - local name="${1}" - local color="${2}" - set -- - set -- $(hexRGBtoDecRGB "${color}") - R=${1}; shift; G=${1}; shift; B=${1}; shift + local name="${1}" + local color="${2}" + set -- + set -- $(hexRGBtoDecRGB "${color}") + R=${1}; shift; G=${1}; shift; B=${1}; shift - echo "${name}=${R},${G},${B}" + echo "${name}=${R},${G},${B}" } updateMinttyConfig () { - local config="${1}" - local color="${2}" - local name="${3}" + local config="${1}" + local color="${2}" + local name="${3}" - sed -i -r -e "s/^${name}=.+/$(createMinttyEntry "${name}" "${color}")/g" "${config}" + sed -i -r -e "s/^${name}=.+/$(createMinttyEntry "${name}" \ +"${color}")/g" "${config}" } convertNameAndRGBtoITerm() { - local name="${1}" - local color="${2}" - set -- - set -- $(convertRGBtoMac "${color}") - R=${1}; shift; G=${1}; shift; B=${1}; shift + local name="${1}" + local color="${2}" + set -- + set -- $(convertRGBtoMac "${color}") + R=${1}; shift; G=${1}; shift; B=${1}; shift - echo "${name}Blue Component${B}Green Component${G}Red Component${R}" + echo "${name}Blue Component${B}\ +Green Component${G}Red Component\ +${R}" } dset() { - local key="${1}"; shift - local val="${1}" + local key="${1}"; shift + local val="${1}" - "${DCONF}" write "${PROFILE_KEY}/${key}" "${val}" + "${DCONF}" write "${PROFILE_KEY}/${key}" "${val}" } # Because dconf still doesn't have "append" dlist_append() { - local key="${1}"; shift - local val="${1}"; shift - local entries + local key="${1}"; shift + local val="${1}"; shift + local entries - entries="$( - { - "${DCONF}" read "${key}" | tr -d "[]" | tr , "\n" | grep -F -v "${val}" - echo "'${val}'" - } | head -c-1 | tr "\n" , - )" + entries="$( + { + "${DCONF}" read "${key}" | tr -d "[]" | tr , "\n" | \ + grep -F -v "${val}" + echo "'${val}'" + } \ + | head -c-1 | tr "\n" , + )" - "${DCONF}" write "${key}" "[${entries}]" + "${DCONF}" write "${key}" "[${entries}]" } gcset() { - local type="${1}"; shift - local key="${1}"; shift - local val="${1}" + local type="${1}"; shift + local key="${1}"; shift + local val="${1}" - "${GCONF}" --set --type "${type}" "${PROFILE_KEY}/${key}" -- "${val}" + "${GCONF}" --set --type "${type}" "${PROFILE_KEY}/${key}" -- "${val}" } # Because gconftool doesn't have "append" glist_append() { - local type="${1}"; shift - local key="${1}"; shift - local val="${1}"; shift - local entries + local type="${1}"; shift + local key="${1}"; shift + local val="${1}"; shift + local entries - entries="$( - { - "${GCONF}" --get "${key}" | tr -d "[]" | tr , "\n" | grep -F -v "${val}" - echo "${val}" - } | head -c-1 | tr "\n" , - )" + entries="$( + { + "${GCONF}" --get "${key}" | tr -d "[]" | tr , "\n" | \ + grep -F -v "${val}" + echo "${val}" + }\ + | head -c-1 | tr "\n" , + )" - "${GCONF}" --set --type list --list-type "${type}" "${key}" "[${entries}]" + "${GCONF}" --set --type list --list-type "${type}" "${key}" \ + "[${entries}]" } gset() { - local key="${1}"; shift - local val="${1}" + local key="${1}"; shift + local val="${1}" - "${GS}" set "${PROFILE_KEY}" "${key}" "${val}" + "${GS}" set "${PROFILE_KEY}" "${key}" "${val}" } set_theme() { - dset visible-name "'${PROFILE_NAME}'" - dset background-color "'${BACKGROUND_COLOR}'" - dset foreground-color "'${FOREGROUND_COLOR}'" + dset visible-name "'${PROFILE_NAME}'" + dset background-color "'${BACKGROUND_COLOR}'" + dset foreground-color "'${FOREGROUND_COLOR}'" - if [[ -n "${HIGHLIGHT_BG_COLOR:-}" ]]; then - dset highlight-colors-set "true" - dset highlight-background-color "'${HIGHLIGHT_BG_COLOR}'" - if [[ -n "${HIGHLIGHT_FG_COLOR:-}" ]]; then - dset highlight-foreground-color "'${HIGHLIGHT_FG_COLOR}'" - fi - fi + if [[ -n "${HIGHLIGHT_BG_COLOR:-}" ]]; then + dset highlight-colors-set "true" + dset highlight-background-color "'${HIGHLIGHT_BG_COLOR}'" + if [[ -n "${HIGHLIGHT_FG_COLOR:-}" ]]; then + dset highlight-foreground-color \ + "'${HIGHLIGHT_FG_COLOR}'" + fi + fi - if [[ -n "${BOLD_COLOR:-}" ]]; then - dset bold-color "'${BOLD_COLOR}'" - dset bold-color-same-as-fg "false" - else - dset bold-color "'${FOREGROUND_COLOR}'" - dset bold-color-same-as-fg "true" - fi - dset use-theme-colors "false" - dset use-theme-background "false" - dset use-theme-transparency "${USE_SYS_TRANSPARENCY:-false}" + if [[ -n "${BOLD_COLOR:-}" ]]; then + dset bold-color "'${BOLD_COLOR}'" + dset bold-color-same-as-fg "false" + else + dset bold-color "'${FOREGROUND_COLOR}'" + dset bold-color-same-as-fg "true" + fi + dset use-theme-colors "false" + dset use-theme-background "false" + dset use-theme-transparency "${USE_SYS_TRANSPARENCY:-false}" } legacy_set_theme() { - gcset string visible_name "${PROFILE_NAME}" - gcset string background_color "${BACKGROUND_COLOR}" - gcset string foreground_color "${FOREGROUND_COLOR}" + gcset string visible_name "${PROFILE_NAME}" + gcset string background_color "${BACKGROUND_COLOR}" + gcset string foreground_color "${FOREGROUND_COLOR}" - if [[ -n "${BOLD_COLOR:-}" ]]; then - gcset string bold_color "${BOLD_COLOR}" - gcset bool bold_color_same_as_fg "false" - else - gcset string bold_color "${FOREGROUND_COLOR}" - gcset bool bold_color_same_as_fg "true" - fi - gcset bool use_theme_colors "false" - gcset bool use_theme_background "false" + if [[ -n "${BOLD_COLOR:-}" ]]; then + gcset string bold_color "${BOLD_COLOR}" + gcset bool bold_color_same_as_fg "false" + else + gcset string bold_color "${FOREGROUND_COLOR}" + gcset bool bold_color_same_as_fg "true" + fi + gcset bool use_theme_colors "false" + gcset bool use_theme_background "false" } # | =========================================== -# | If terminal supports truecolor then we can show theme colors without applying the theme +# | If terminal supports truecolor then we can show theme colors without +# | applying the theme # | =========================================== -if [[ "${COLORTERM:-}" == "truecolor" ]] || [[ "${COLORTERM:-}" == "24bit" ]]; then - # gogh_colors have been moved here to avoid multiple definitions - function gogh_colors () { - # Build up the color string to avoid visual rendering - local color_str - # Note: {01..16} does not work on OSX - for c in $(seq -s " " -w 16); do - local color="COLOR_$c" - set -- $(hexRGBtoDecRGB "${!color}") - color_str+="\033[38;2;${1};${2};${3}m█████$(tput sgr0)" - [[ ${GOGH_DRY_RUN:-0} -eq 1 ]] && export "DEMO_COLOR_$c=\033[38;2;${1};${2};${3}m" - [[ "$c" == "08" ]] && color_str+="\n" # new line - done - printf '\n%b\n\n\n' "${color_str}" - unset color_str - } +if [[ "${COLORTERM:-}" == "truecolor" ]] || [[ "${COLORTERM:-}" == "24bit" ]] +then + # gogh_colors have been moved here to avoid multiple definitions + function gogh_colors () { + # Build up the color string to avoid visual rendering + local color_str + # Note: {01..16} does not work on OSX + for c in $(seq -s " " -w 16); do + local color="COLOR_$c" + set -- $(hexRGBtoDecRGB "${!color}") + color_str+="\033[38;2;${1};${2};${3}m█████$(tput sgr0)" + [[ ${GOGH_DRY_RUN:-0} -eq 1 ]] && \ + export "DEMO_COLOR_$c=\033[38;2;${1};${2};${3}m" + [[ "$c" == "08" ]] && \ + color_str+="\n" # new line + done + printf '\n%b\n\n\n' "${color_str}" + unset color_str + } else - function gogh_colors () { - # Build up the color string to avoid visual rendering - local color_str - for c in {0..15}; do - color_str+="$(tput setaf $c)█████$(tput sgr0)" - [[ $c == 7 ]] && color_str+="\n" # new line - done - printf '\n%b\n\n' "${color_str}" - unset color_str - } + function gogh_colors () { + # Build up the color string to avoid visual rendering + local color_str + for c in {0..15}; do + color_str+="$(tput setaf $c)█████$(tput sgr0)" + [[ $c == 7 ]] && color_str+="\n" # new line + done + printf '\n%b\n\n' "${color_str}" + unset color_str + } fi # | =========================================== @@ -336,417 +349,440 @@ fi # | =========================================== gogh_colors if [[ ${GOGH_DRY_RUN:-0} -eq 1 ]]; then - color - # End here if dry run was initiated - exit 0 + color + # End here if dry run was initiated + exit 0 fi apply_elementary() { - # | =========================================== - # | Applying values on elementary/pantheon terminal - # | =========================================== - gset background "${BACKGROUND_COLOR}" - gset foreground "${FOREGROUND_COLOR}" - gset cursor-color "${CURSOR_COLOR}" - gset palette "${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}" + # | =========================================== + # | Applying values on elementary/pantheon terminal + # | =========================================== + gset background "${BACKGROUND_COLOR}" + gset foreground "${FOREGROUND_COLOR}" + gset cursor-color "${CURSOR_COLOR}" + gset palette "${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}" } apply_cygwin() { - # | =========================================== - # | Applying values on mintty (cygwin) - # | =========================================== + # | =========================================== + # | Applying values on mintty (cygwin) + # | =========================================== - echo "Patching mintty configuration file (${CFGFILE}) with new colors..." + echo "Patching mintty configuration file (${CFGFILE}) with new colors..." - updateMinttyConfig "$CFGFILE" "$COLOR_01" "Black" - updateMinttyConfig "$CFGFILE" "$COLOR_02" "Red" - updateMinttyConfig "$CFGFILE" "$COLOR_03" "Green" - updateMinttyConfig "$CFGFILE" "$COLOR_04" "Yellow" - updateMinttyConfig "$CFGFILE" "$COLOR_05" "Blue" - updateMinttyConfig "$CFGFILE" "$COLOR_06" "Magenta" - updateMinttyConfig "$CFGFILE" "$COLOR_07" "Cyan" - updateMinttyConfig "$CFGFILE" "$COLOR_08" "White" + updateMinttyConfig "$CFGFILE" "$COLOR_01" "Black" + updateMinttyConfig "$CFGFILE" "$COLOR_02" "Red" + updateMinttyConfig "$CFGFILE" "$COLOR_03" "Green" + updateMinttyConfig "$CFGFILE" "$COLOR_04" "Yellow" + updateMinttyConfig "$CFGFILE" "$COLOR_05" "Blue" + updateMinttyConfig "$CFGFILE" "$COLOR_06" "Magenta" + updateMinttyConfig "$CFGFILE" "$COLOR_07" "Cyan" + updateMinttyConfig "$CFGFILE" "$COLOR_08" "White" - updateMinttyConfig "$CFGFILE" "$COLOR_09" "BoldBlack" - updateMinttyConfig "$CFGFILE" "$COLOR_10" "BoldRed" - updateMinttyConfig "$CFGFILE" "$COLOR_11" "BoldGreen" - updateMinttyConfig "$CFGFILE" "$COLOR_12" "BoldYellow" - updateMinttyConfig "$CFGFILE" "$COLOR_13" "BoldBlue" - updateMinttyConfig "$CFGFILE" "$COLOR_14" "BoldMagenta" - updateMinttyConfig "$CFGFILE" "$COLOR_15" "BoldCyan" - updateMinttyConfig "$CFGFILE" "$COLOR_16" "BoldWhite" + updateMinttyConfig "$CFGFILE" "$COLOR_09" "BoldBlack" + updateMinttyConfig "$CFGFILE" "$COLOR_10" "BoldRed" + updateMinttyConfig "$CFGFILE" "$COLOR_11" "BoldGreen" + updateMinttyConfig "$CFGFILE" "$COLOR_12" "BoldYellow" + updateMinttyConfig "$CFGFILE" "$COLOR_13" "BoldBlue" + updateMinttyConfig "$CFGFILE" "$COLOR_14" "BoldMagenta" + updateMinttyConfig "$CFGFILE" "$COLOR_15" "BoldCyan" + updateMinttyConfig "$CFGFILE" "$COLOR_16" "BoldWhite" - updateMinttyConfig "$CFGFILE" "$BACKGROUND_COLOR" "Backgroundcolor" - updateMinttyConfig "$CFGFILE" "$FOREGROUND_COLOR" "Foregroundcolor" - updateMinttyConfig "$CFGFILE" "$CURSOR_COLOR" "Cursorcolor" + updateMinttyConfig "$CFGFILE" "$BACKGROUND_COLOR" "Backgroundcolor" + updateMinttyConfig "$CFGFILE" "$FOREGROUND_COLOR" "Foregroundcolor" + updateMinttyConfig "$CFGFILE" "$CURSOR_COLOR" "Cursorcolor" - echo "Done - please reopen your Cygwin terminal to see the changes" + echo "Done - please reopen your Cygwin terminal to see the changes" } apply_darwin() { - # | =========================================== - # | Applying values on iTerm2 - # | =========================================== + # | =========================================== + # | Applying values on iTerm2 + # | =========================================== - BACKGROUND_COLOR=$(convertNameAndRGBtoITerm "Background Color" "$BACKGROUND_COLOR") - FOREGROUND_COLOR=$(convertNameAndRGBtoITerm "Foreground Color" "$FOREGROUND_COLOR") - COLOR_01=$(convertNameAndRGBtoITerm "Ansi 0 Color" "$COLOR_01") - COLOR_02=$(convertNameAndRGBtoITerm "Ansi 1 Color" "$COLOR_02") - COLOR_03=$(convertNameAndRGBtoITerm "Ansi 2 Color" "$COLOR_03") - COLOR_04=$(convertNameAndRGBtoITerm "Ansi 3 Color" "$COLOR_04") - COLOR_05=$(convertNameAndRGBtoITerm "Ansi 4 Color" "$COLOR_05") - COLOR_06=$(convertNameAndRGBtoITerm "Ansi 5 Color" "$COLOR_06") - COLOR_07=$(convertNameAndRGBtoITerm "Ansi 6 Color" "$COLOR_07") - COLOR_08=$(convertNameAndRGBtoITerm "Ansi 7 Color" "$COLOR_08") - COLOR_09=$(convertNameAndRGBtoITerm "Ansi 8 Color" "$COLOR_09") - COLOR_10=$(convertNameAndRGBtoITerm "Ansi 9 Color" "$COLOR_10") - COLOR_11=$(convertNameAndRGBtoITerm "Ansi 10 Color" "$COLOR_11") - COLOR_12=$(convertNameAndRGBtoITerm "Ansi 11 Color" "$COLOR_12") - COLOR_13=$(convertNameAndRGBtoITerm "Ansi 12 Color" "$COLOR_13") - COLOR_14=$(convertNameAndRGBtoITerm "Ansi 13 Color" "$COLOR_14") - COLOR_15=$(convertNameAndRGBtoITerm "Ansi 14 Color" "$COLOR_15") - COLOR_16=$(convertNameAndRGBtoITerm "Ansi 15 Color" "$COLOR_16") + BACKGROUND_COLOR=$(convertNameAndRGBtoITerm "Background Color" \ + "$BACKGROUND_COLOR") + FOREGROUND_COLOR=$(convertNameAndRGBtoITerm "Foreground Color" \ + "$FOREGROUND_COLOR") + COLOR_01=$(convertNameAndRGBtoITerm "Ansi 0 Color" \ + "$COLOR_01") + COLOR_02=$(convertNameAndRGBtoITerm "Ansi 1 Color" \ + "$COLOR_02") + COLOR_03=$(convertNameAndRGBtoITerm "Ansi 2 Color" \ + "$COLOR_03") + COLOR_04=$(convertNameAndRGBtoITerm "Ansi 3 Color" \ + "$COLOR_04") + COLOR_05=$(convertNameAndRGBtoITerm "Ansi 4 Color" \ + "$COLOR_05") + COLOR_06=$(convertNameAndRGBtoITerm "Ansi 5 Color" \ + "$COLOR_06") + COLOR_07=$(convertNameAndRGBtoITerm "Ansi 6 Color" \ + "$COLOR_07") + COLOR_08=$(convertNameAndRGBtoITerm "Ansi 7 Color" \ + "$COLOR_08") + COLOR_09=$(convertNameAndRGBtoITerm "Ansi 8 Color" \ + "$COLOR_09") + COLOR_10=$(convertNameAndRGBtoITerm "Ansi 9 Color" \ + "$COLOR_10") + COLOR_11=$(convertNameAndRGBtoITerm "Ansi 10 Color" \ + "$COLOR_11") + COLOR_12=$(convertNameAndRGBtoITerm "Ansi 11 Color" \ + "$COLOR_12") + COLOR_13=$(convertNameAndRGBtoITerm "Ansi 12 Color" \ + "$COLOR_13") + COLOR_14=$(convertNameAndRGBtoITerm "Ansi 13 Color" \ + "$COLOR_14") + COLOR_15=$(convertNameAndRGBtoITerm "Ansi 14 Color" \ + "$COLOR_15") + COLOR_16=$(convertNameAndRGBtoITerm "Ansi 15 Color" \ + "$COLOR_16") - # Assemble color scheme file contents - ITERMCOLORS=''${BACKGROUND_COLOR}${FOREGROUND_COLOR}${COLOR_01}${COLOR_02}${COLOR_03}${COLOR_04}${COLOR_05}${COLOR_06}${COLOR_07}${COLOR_08}${COLOR_09}${COLOR_10}${COLOR_11}${COLOR_12}${COLOR_13}${COLOR_14}${COLOR_15}'' + # Assemble color scheme file contents + ITERMCOLORS=''${BACKGROUND_COLOR}${FOREGROUND_COLOR}${COLOR_01}${COLOR_02}${COLOR_03}${COLOR_04}${COLOR_05}${COLOR_06}${COLOR_07}${COLOR_08}${COLOR_09}${COLOR_10}${COLOR_11}${COLOR_12}${COLOR_13}${COLOR_14}${COLOR_15}'' - # Dump iTerm color scheme to file and import it by opening it - echo "${ITERMCOLORS}" > "${PROFILE_NAME}.itermcolors" - open "${PROFILE_NAME}.itermcolors" - rm "${PROFILE_NAME}.itermcolors" + # Dump iTerm color scheme to file and import it by opening it + echo "${ITERMCOLORS}" > "${PROFILE_NAME}.itermcolors" + open "${PROFILE_NAME}.itermcolors" + rm "${PROFILE_NAME}.itermcolors" } apply_gtk() { - # | =========================================== - # | Applying values to gnome/mate/tilix - # | =========================================== + # | =========================================== + # | Applying values to gnome/mate/tilix + # | =========================================== - local legacy="${1:-}" + local legacy="${1:-}" - # This is to avoid doing the profile loop definition twice - if [[ -z "${legacy}" ]]; then - CONFTOOL="${DCONF} read" - VISIBLE_NAME="visible-name" - else - CONFTOOL="${GCONF} --get" - VISIBLE_NAME="visible_name" - fi + # This is to avoid doing the profile loop definition twice + if [[ -z "${legacy}" ]]; then + CONFTOOL="${DCONF} read" + VISIBLE_NAME="visible-name" + else + CONFTOOL="${GCONF} --get" + VISIBLE_NAME="visible_name" + fi - # Check first wether profile already exists - profile_hashes=($(${CONFTOOL} "${PROFILE_LIST_KEY}" | tr "[]'," " ")) - for profile in "${profile_hashes[@]}"; do - if [[ "$(${CONFTOOL} "${BASE_DIR}${profile}/${VISIBLE_NAME}" | tr -d "'")" == "${PROFILE_NAME}" ]]; then - printf '%s\n' "Profile already exists" "Skipping..." - exit 0 - fi - done + # Check first wether profile already exists + profile_hashes=($(${CONFTOOL} "${PROFILE_LIST_KEY}" | tr "[]'," " ")) + for profile in "${profile_hashes[@]}"; do + if [[ "$(${CONFTOOL} "${BASE_DIR}${profile}/${VISIBLE_NAME}" | \ + tr -d "'")" == "${PROFILE_NAME}" ]]; then + printf '%s\n' "Profile already exists" "Skipping..." + exit 0 + fi + done - # Fallback if there is no default profile - set -- $(${CONFTOOL} ${PROFILE_LIST_KEY} | tr "[]'," " ") - : ${DEFAULT_SLUG:="$1"} + # Fallback if there is no default profile + set -- $(${CONFTOOL} ${PROFILE_LIST_KEY} | tr "[]'," " ") + : ${DEFAULT_SLUG:="$1"} - : ${PROFILE_NAME:="Default"} - : ${PROFILE_SLUG:="Default"} + : ${PROFILE_NAME:="Default"} + : ${PROFILE_SLUG:="Default"} - DEFAULT_KEY="${BASE_DIR}${DEFAULT_SLUG:-}" - PROFILE_KEY="${BASE_DIR}${PROFILE_SLUG:-}" + DEFAULT_KEY="${BASE_DIR}${DEFAULT_SLUG:-}" + PROFILE_KEY="${BASE_DIR}${PROFILE_SLUG:-}" - if [[ -z "${legacy}" ]]; then - if [[ -z "$(${DCONF} list ${BASE_DIR%:})" ]]; then - # Provide a user friendly error text if no saved profile exists, otherwise it will display "Error gconftool not found!" - # it could happen on a newly installed system. (happened on CentOS 7) - printf '%s\n' \ - "Error, no saved profiles found!" \ - "Possible fix, new a profile (Terminal > Edit > Preferences > Profiles > New, then Close) and try again." \ - "You can safely delete the created profile after the installation." - exit 1 - fi + if [[ -z "${legacy}" ]]; then + # Provide a user friendly error text if no saved profile exists, + # otherwise it will display "Error gconftool not found!" + # it could happen on a newly installed system + if [[ -z "$(${DCONF} list ${BASE_DIR%:})" ]]; then + printf '%s\n' \ + "Error, no saved profiles found!" \ + "Possible fix, new a profile (Terminal > Edit > Pref\ +erences > Profiles > New, then Close) and try again." \ + "You can safely delete the created profile after the\ +installation." + exit 1 + fi - BACKGROUND_COLOR=$(gnome_color "$BACKGROUND_COLOR") - FOREGROUND_COLOR=$(gnome_color "$FOREGROUND_COLOR") - HIGHLIGHT_BG_COLOR=$(gnome_color "$HIGHLIGHT_BG_COLOR") - HIGHLIGHT_FG_COLOR=$(gnome_color "$HIGHLIGHT_FG_COLOR") - COLOR_01=$(gnome_color "$COLOR_01") - COLOR_02=$(gnome_color "$COLOR_02") - COLOR_03=$(gnome_color "$COLOR_03") - COLOR_04=$(gnome_color "$COLOR_04") - COLOR_05=$(gnome_color "$COLOR_05") - COLOR_06=$(gnome_color "$COLOR_06") - COLOR_07=$(gnome_color "$COLOR_07") - COLOR_08=$(gnome_color "$COLOR_08") - COLOR_09=$(gnome_color "$COLOR_09") - COLOR_10=$(gnome_color "$COLOR_10") - COLOR_11=$(gnome_color "$COLOR_11") - COLOR_12=$(gnome_color "$COLOR_12") - COLOR_13=$(gnome_color "$COLOR_13") - COLOR_14=$(gnome_color "$COLOR_14") - COLOR_15=$(gnome_color "$COLOR_15") - COLOR_16=$(gnome_color "$COLOR_16") + BACKGROUND_COLOR=$(gnome_color "$BACKGROUND_COLOR") + FOREGROUND_COLOR=$(gnome_color "$FOREGROUND_COLOR") + HIGHLIGHT_BG_COLOR=$(gnome_color "$HIGHLIGHT_BG_COLOR") + HIGHLIGHT_FG_COLOR=$(gnome_color "$HIGHLIGHT_FG_COLOR") + COLOR_01=$(gnome_color "$COLOR_01") + COLOR_02=$(gnome_color "$COLOR_02") + COLOR_03=$(gnome_color "$COLOR_03") + COLOR_04=$(gnome_color "$COLOR_04") + COLOR_05=$(gnome_color "$COLOR_05") + COLOR_06=$(gnome_color "$COLOR_06") + COLOR_07=$(gnome_color "$COLOR_07") + COLOR_08=$(gnome_color "$COLOR_08") + COLOR_09=$(gnome_color "$COLOR_09") + COLOR_10=$(gnome_color "$COLOR_10") + COLOR_11=$(gnome_color "$COLOR_11") + COLOR_12=$(gnome_color "$COLOR_12") + COLOR_13=$(gnome_color "$COLOR_13") + COLOR_14=$(gnome_color "$COLOR_14") + COLOR_15=$(gnome_color "$COLOR_15") + COLOR_16=$(gnome_color "$COLOR_16") - # copy existing settings from default profile - $DCONF dump "${DEFAULT_KEY}/" | $DCONF load "${PROFILE_KEY}/" + # copy existing settings from default profile + $DCONF dump "${DEFAULT_KEY}/" | \ + $DCONF load "${PROFILE_KEY}/" - # add new copy to global list of profiles - dlist_append "${PROFILE_LIST_KEY}" "${PROFILE_SLUG#:}" + # add new copy to global list of profiles + dlist_append "${PROFILE_LIST_KEY}" "${PROFILE_SLUG#:}" - set_theme - dset palette "${LEFT_WRAPPER:-}'${COLOR_01}${PALETTE_DELIM}${COLOR_02}${PALETTE_DELIM}${COLOR_03}${PALETTE_DELIM}${COLOR_04}${PALETTE_DELIM}${COLOR_05}${PALETTE_DELIM}${COLOR_06}${PALETTE_DELIM}${COLOR_07}${PALETTE_DELIM}${COLOR_08}${PALETTE_DELIM}${COLOR_09}${PALETTE_DELIM}${COLOR_10}${PALETTE_DELIM}${COLOR_11}${PALETTE_DELIM}${COLOR_12}${PALETTE_DELIM}${COLOR_13}${PALETTE_DELIM}${COLOR_14}${PALETTE_DELIM}${COLOR_15}${PALETTE_DELIM}${COLOR_16}'${RIGHT_WRAPPER:-}" - ${LEGACY_BOLD:-} && dset allow-bold "true" # mate - else - # Append the Base16 profile to the profile list - glist_append string "${PROFILE_LIST_KEY}" "${PROFILE_SLUG}" + set_theme + dset palette "${LEFT_WRAPPER:-}'${COLOR_01}${PALETTE_DELIM}${COLOR_02}${PALETTE_DELIM}${COLOR_03}${PALETTE_DELIM}${COLOR_04}${PALETTE_DELIM}${COLOR_05}${PALETTE_DELIM}${COLOR_06}${PALETTE_DELIM}${COLOR_07}${PALETTE_DELIM}${COLOR_08}${PALETTE_DELIM}${COLOR_09}${PALETTE_DELIM}${COLOR_10}${PALETTE_DELIM}${COLOR_11}${PALETTE_DELIM}${COLOR_12}${PALETTE_DELIM}${COLOR_13}${PALETTE_DELIM}${COLOR_14}${PALETTE_DELIM}${COLOR_15}${PALETTE_DELIM}${COLOR_16}'${RIGHT_WRAPPER:-}" + ${LEGACY_BOLD:-} && dset allow-bold "true" # mate + else + # Append the Base16 profile to the profile list + glist_append string "${PROFILE_LIST_KEY}" "${PROFILE_SLUG}" - legacy_set_theme - gcset string palette "${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}" - ${LEGACY_BOLD:-} && gcset bool allow-bold "true" - fi + legacy_set_theme + gcset string palette "${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}" + ${LEGACY_BOLD:-} && gcset bool allow-bold "true" + fi } apply_guake() { - # | =========================================== - # | Applying values to guake - # | =========================================== + # | =========================================== + # | Applying values to guake + # | =========================================== - local legacy="${1:-}" - PROFILE_KEY="/apps/guake/style/font" + local legacy="${1:-}" + PROFILE_KEY="/apps/guake/style/font" - if [[ -z "${legacy}" ]]; then - dset palette "'${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}:${FOREGROUND_COLOR}:${BACKGROUND_COLOR}'" - dset palette-name "'${PROFILE_NAME}'" - dset allow-bold 'true' - else - gcset string color "${FOREGROUND_COLOR}" - gcset string palette "${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}" - gcset string palette-name "${PROFILE_NAME}" - PROFILE_KEY="/apps/guake/style/background" - gcset string color "${BACKGROUND_COLOR}" + if [[ -z "${legacy}" ]]; then + dset palette "'${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}:${FOREGROUND_COLOR}:${BACKGROUND_COLOR}'" + dset palette-name "'${PROFILE_NAME}'" + dset allow-bold 'true' + else + gcset string color "${FOREGROUND_COLOR}" + gcset string palette "${COLOR_01}:${COLOR_02}:${COLOR_03}:${COLOR_04}:${COLOR_05}:${COLOR_06}:${COLOR_07}:${COLOR_08}:${COLOR_09}:${COLOR_10}:${COLOR_11}:${COLOR_12}:${COLOR_13}:${COLOR_14}:${COLOR_15}:${COLOR_16}" + gcset string palette-name "${PROFILE_NAME}" + PROFILE_KEY="/apps/guake/style/background" + gcset string color "${BACKGROUND_COLOR}" - fi + fi } appy_tilixschemes() { - # | =========================================== - # | Applying values to tilix colorschemes - # | =========================================== + # | =========================================== + # | Applying values to tilix colorschemes + # | =========================================== - if [[ ${TILIX_RES::1} =~ ^(y|Y)$ ]]; then - [[ -d "${HOME}/.config/tilix/schemes" ]] || mkdir -p "${HOME}/.config/tilix/schemes" + if [[ ${TILIX_RES::1} =~ ^(y|Y)$ ]]; then + [[ -d "${HOME}/.config/tilix/schemes" ]] || mkdir -p "${HOME}/.config/tilix/schemes" - TILIXCOLORS='{\n\t"name": "'${PROFILE_NAME}'",\n\t"comment": "Generated by Gogh",\n\t"foreground-color": "'${FOREGROUND_COLOR}'",\n\t"background-color":"'${BACKGROUND_COLOR}'",\n\t"cursor-background-color": "'${CURSOR_COLOR}'",\n\t"palette": [\n\t\t"'${COLOR_01}'",\n\t\t"'${COLOR_02}'",\n\t\t"'${COLOR_03}'",\n\t\t"'${COLOR_04}'",\n\t\t"'${COLOR_05}'",\n\t\t"'${COLOR_06}'",\n\t\t"'${COLOR_07}'",\n\t\t"'${COLOR_08}'",\n\t\t"'${COLOR_09}'",\n\t\t"'${COLOR_10}'",\n\t\t"'${COLOR_11}'",\n\t\t"'${COLOR_12}'",\n\t\t"'${COLOR_13}'",\n\t\t"'${COLOR_14}'",\n\t\t"'${COLOR_15}'",\n\t\t"'${COLOR_16}'"\n\t],\n\t"use-badge-color": false,\n\t"use-bold-color": false,\n\t"use-cursor-color": false,\n\t"use-highlight-color": false,\n\t"use-theme-colors": false\n}' - echo -e "${TILIXCOLORS}" > "${scratchdir}/${PROFILE_NAME}.json" + TILIXCOLORS='{\n\t"name": "'${PROFILE_NAME}'",\n\t"comment": "Generated by Gogh",\n\t"foreground-color": "'${FOREGROUND_COLOR}'",\n\t"background-color":"'${BACKGROUND_COLOR}'",\n\t"cursor-background-color": "'${CURSOR_COLOR}'",\n\t"palette": [\n\t\t"'${COLOR_01}'",\n\t\t"'${COLOR_02}'",\n\t\t"'${COLOR_03}'",\n\t\t"'${COLOR_04}'",\n\t\t"'${COLOR_05}'",\n\t\t"'${COLOR_06}'",\n\t\t"'${COLOR_07}'",\n\t\t"'${COLOR_08}'",\n\t\t"'${COLOR_09}'",\n\t\t"'${COLOR_10}'",\n\t\t"'${COLOR_11}'",\n\t\t"'${COLOR_12}'",\n\t\t"'${COLOR_13}'",\n\t\t"'${COLOR_14}'",\n\t\t"'${COLOR_15}'",\n\t\t"'${COLOR_16}'"\n\t],\n\t"use-badge-color": false,\n\t"use-bold-color": false,\n\t"use-cursor-color": false,\n\t"use-highlight-color": false,\n\t"use-theme-colors": false\n}' + echo -e "${TILIXCOLORS}" > "${scratchdir}/${PROFILE_NAME}.json" - # Note: Tilix does not store color scheme name in dconf - # so we have to update color palette for the current profile in order to switch to the new theme - # but only set the palette on the last loop to avoid a flashing terminal - if ((LOOP == OPTLENGTH)); then - cp -f ${scratchdir}/* "$HOME/.config/tilix/schemes/" - rm -rf "${scratchdir}" - read -r -p "All done - apply new theme? [y/N] " -n 1 TILIX_RES - if [[ ${TILIX_RES::1} =~ ^(y|Y)$ ]]; then - PROFILE_KEY="${BASE_DIR}${DEFAULT_SLUG}" - PROFILE_NAME="$(${DCONF} read ${PROFILE_KEY}/visible-name | tr -d \')" - set_theme - dset palette "['${COLOR_01}', '${COLOR_02}', '${COLOR_03}', '${COLOR_04}', '${COLOR_05}', '${COLOR_06}', '${COLOR_07}', '${COLOR_08}', '${COLOR_09}', '${COLOR_10}', '${COLOR_11}', '${COLOR_12}', '${COLOR_13}', '${COLOR_14}', '${COLOR_15}', '${COLOR_16}']" - fi - fi + # Note: Tilix does not store color scheme name in dconf + # so we have to update color palette for the current profile in order to switch to the new theme + # but only set the palette on the last loop to avoid a flashing terminal + if ((LOOP == OPTLENGTH)); then + cp -f ${scratchdir}/* "$HOME/.config/tilix/schemes/" + rm -rf "${scratchdir}" + read -r -p "All done - apply new theme? [y/N] " -n 1 TILIX_RES + if [[ ${TILIX_RES::1} =~ ^(y|Y)$ ]]; then + PROFILE_KEY="${BASE_DIR}${DEFAULT_SLUG}" + PROFILE_NAME="$(${DCONF} read ${PROFILE_KEY}/visible-name | tr -d \')" + set_theme + dset palette "['${COLOR_01}', '${COLOR_02}', '${COLOR_03}', '${COLOR_04}', '${COLOR_05}', '${COLOR_06}', '${COLOR_07}', '${COLOR_08}', '${COLOR_09}', '${COLOR_10}', '${COLOR_11}', '${COLOR_12}', '${COLOR_13}', '${COLOR_14}', '${COLOR_15}', '${COLOR_16}']" + fi + fi - unset PROFILE_NAME - unset PROFILE_SLUG - unset TILIXCOLORS - exit 0 - fi + unset PROFILE_NAME + unset PROFILE_SLUG + unset TILIXCOLORS + exit 0 + fi } apply_xfce4-terminal() { - # XFCE4 terminal has no profiles, instead it uses color presets - SCHEMEDIR="${HOME}/.local/share/xfce4/terminal/colorschemes" - CONFFILE="${HOME}/.config/xfce4/terminal/terminalrc" + # XFCE4 terminal has no profiles, instead it uses color presets + SCHEMEDIR="${HOME}/.local/share/xfce4/terminal/colorschemes" + CONFFILE="${HOME}/.config/xfce4/terminal/terminalrc" - if [[ ! (-w "${CONFFILE}") ]]; then - if [[ -r "${XDG_CONFIG_DIRS%%:*}/Terminal/terminalrc" ]]; then - cp "${XDG_CONFIG_DIRS%%:*}/Terminal/terminalrc" ${CONFFILE} - else - echo "ERROR: config file not present or not writable!" - exit 1 + if [[ ! (-w "${CONFFILE}") ]]; then + if [[ -r "${XDG_CONFIG_DIRS%%:*}/Terminal/terminalrc" ]]; then + cp "${XDG_CONFIG_DIRS%%:*}/Terminal/terminalrc" ${CONFFILE} + else + echo "ERROR: config file not present or not writable!" + exit 1 + fi fi - fi - [[ -d "${SCHEMEDIR}" ]] || mkdir -p "${SCHEMEDIR}" + [[ -d "${SCHEMEDIR}" ]] || mkdir -p "${SCHEMEDIR}" - F_NAME=${PROFILE_NAME// /-} - F_NAME=$(echo ${F_NAME} | tr -d ":()") - F_NAME=$(echo "${F_NAME}" | awk '{print tolower($0)}') + F_NAME=${PROFILE_NAME// /-} + F_NAME=$(echo ${F_NAME} | tr -d ":()") + F_NAME=$(echo "${F_NAME}" | awk '{print tolower($0)}') - FF_NAME="${SCHEMEDIR}/${F_NAME}.theme" + FF_NAME="${SCHEMEDIR}/${F_NAME}.theme" - touch "${FF_NAME}" + touch "${FF_NAME}" - L_COLORCURSOR="ColorCursor=${CURSOR_COLOR}" - L_COLORPALETTE="ColorPalette=${COLOR_01};${COLOR_02};${COLOR_03};${COLOR_04};${COLOR_05};${COLOR_06};${COLOR_07};${COLOR_08};${COLOR_09};${COLOR_10};${COLOR_11};${COLOR_12};${COLOR_13};${COLOR_14};${COLOR_15};${COLOR_16}" + L_COLORCURSOR="ColorCursor=${CURSOR_COLOR}" + L_COLORPALETTE="ColorPalette=${COLOR_01};${COLOR_02};${COLOR_03};${COLOR_04};${COLOR_05};${COLOR_06};${COLOR_07};${COLOR_08};${COLOR_09};${COLOR_10};${COLOR_11};${COLOR_12};${COLOR_13};${COLOR_14};${COLOR_15};${COLOR_16}" - printf '%s\n' \ - "; Generated by Gogh" \ - "; https://mayccoll.github.io/Gogh" \ - "[Scheme]" \ - "Name=${PROFILE_NAME}" \ - "ColorForeground=${FOREGROUND_COLOR}" \ - "ColorBackground=${BACKGROUND_COLOR}" \ - "${L_COLORCURSOR}" \ - "${L_COLORPALETTE}" \ - "ColorCursorUseDefault=FALSE" > ${FF_NAME} + printf '%s\n' \ + "; Generated by Gogh" \ + "; https://mayccoll.github.io/Gogh" \ + "[Scheme]" \ + "Name=${PROFILE_NAME}" \ + "ColorForeground=${FOREGROUND_COLOR}" \ + "ColorBackground=${BACKGROUND_COLOR}" \ + "${L_COLORCURSOR}" \ + "${L_COLORPALETTE}" \ + "ColorCursorUseDefault=FALSE" > ${FF_NAME} - # apply last theme in queue - # xfce4-terminal monitors its rc file and doesn't reference - # any of the themes in there. The color settings need to - # be written there directly. - if ((LOOP == OPTLENGTH)); then - read -r -p "All done - apply new theme? [y/N] " -n 1 XFCE4_APPLY_CURR_THEME - if [[ ${XFCE4_APPLY_CURR_THEME::1} =~ ^(y|Y)$ ]]; then - if grep -q "^ColorPalette=" "${CONFFILE}"; then - sed -i -r -e "s/^ColorPalette=.*/${L_COLORPALETTE}/" "${CONFFILE}" - else - echo "${L_COLORPALETTE}" >> "${CONFFILE}" - fi + # apply last theme in queue + # xfce4-terminal monitors its rc file and doesn't reference + # any of the themes in there. The color settings need to + # be written there directly. + if ((LOOP == OPTLENGTH)); then + read -r -p "All done - apply new theme? [y/N] " -n 1 XFCE4_APPLY_CURR_THEME + if [[ ${XFCE4_APPLY_CURR_THEME::1} =~ ^(y|Y)$ ]]; then + if grep -q "^ColorPalette=" "${CONFFILE}"; then + sed -i -r -e "s/^ColorPalette=.*/${L_COLORPALETTE}/" "${CONFFILE}" + else + echo "${L_COLORPALETTE}" >> "${CONFFILE}" + fi - if grep -q "^ColorCursor=" "${CONFFILE}"; then - sed -i -r -e "s/^ColorCursor=.*/${L_COLORCURSOR}/" "${CONFFILE}" - else - echo "${L_COLORCURSOR}" >> "${CONFFILE}" - fi + if grep -q "^ColorCursor=" "${CONFFILE}"; then + sed -i -r -e "s/^ColorCursor=.*/${L_COLORCURSOR}/" "${CONFFILE}" + else + echo "${L_COLORCURSOR}" >> "${CONFFILE}" + fi - if grep -q "^ColorForeground=" "${CONFFILE}"; then - sed -i -r -e "s/^ColorForeground=.*/ColorForeground=${FOREGROUND_COLOR}/" "${CONFFILE}" - else - echo "ColorForeground=${FOREGROUND_COLOR}" >> "${CONFFILE}" - fi + if grep -q "^ColorForeground=" "${CONFFILE}"; then + sed -i -r -e "s/^ColorForeground=.*/ColorForeground=${FOREGROUND_COLOR}/" "${CONFFILE}" + else + echo "ColorForeground=${FOREGROUND_COLOR}" >> "${CONFFILE}" + fi - if grep -q "^ColorBackground=" "${CONFFILE}"; then - sed -i -r -e "s/^ColorBackground=.*/ColorBackground=${BACKGROUND_COLOR}/" "${CONFFILE}" - else - echo "ColorBackground=${BACKGROUND_COLOR}" >> "${CONFFILE}" - fi + if grep -q "^ColorBackground=" "${CONFFILE}"; then + sed -i -r -e "s/^ColorBackground=.*/ColorBackground=${BACKGROUND_COLOR}/" "${CONFFILE}" + else + echo "ColorBackground=${BACKGROUND_COLOR}" >> "${CONFFILE}" + fi - if grep -q "^ColorCursorUseDefault=FALSE" "${CONFFILE}"; then - true - else - echo "ColorCursorUseDefault=FALSE" >> "${CONFFILE}" - fi + if grep -q "^ColorCursorUseDefault=FALSE" "${CONFFILE}"; then + true + else + echo "ColorCursorUseDefault=FALSE" >> "${CONFFILE}" + fi + fi fi - fi - unset SCHEMEDIR - unset CONFFILE - unset PROFILE_NAME - unset F_NAME - unset FF_NAME - unset L_COLORCURSOR - unset L_COLORPALETTE - exit 0 + unset SCHEMEDIR + unset CONFFILE + unset PROFILE_NAME + unset F_NAME + unset FF_NAME + unset L_COLORCURSOR + unset L_COLORPALETTE + exit 0 } [[ -n "${UUIDGEN}" ]] && PROFILE_SLUG="$(uuidgen)" case "${TERMINAL}" in - pantheon-terminal|io.elementary.t* ) - if [[ "${TERMINAL}" == "pantheon-terminal" ]]; then - PROFILE_KEY="org.pantheon.terminal.settings" - else - PROFILE_KEY="io.elementary.terminal.settings" - fi - apply_elementary - ;; +pantheon-terminal|io.elementary.t* ) + if [[ "${TERMINAL}" == "pantheon-terminal" ]]; then + PROFILE_KEY="org.pantheon.terminal.settings" + else + PROFILE_KEY="io.elementary.terminal.settings" + fi + apply_elementary + ;; - iTerm.app ) - apply_darwin - ;; +iTerm.app ) + apply_darwin + ;; - mintty ) - apply_cygwin - ;; +mintty ) + apply_cygwin + ;; - guake ) - if [[ -n "$(${DCONF} list /apps/guake/style/)" ]]; then - apply_guake - else - apply_guake legacy - fi - ;; +guake ) + if [[ -n "$(${DCONF} list /apps/guake/style/)" ]]; then + apply_guake + else + apply_guake legacy + fi + ;; - gnome-terminal* ) - if [[ -n "$(${DCONF} list /org/gnome/terminal/)" ]]; then - BASE_DIR="/org/gnome/terminal/legacy/profiles:/:" - PROFILE_LIST_KEY="${BASE_DIR%:}list" - PROFILE_SLUG="${PROFILE_SLUG}" +gnome-terminal* ) + if [[ -n "$(${DCONF} list /org/gnome/terminal/)" ]]; then + BASE_DIR="/org/gnome/terminal/legacy/profiles:/:" + PROFILE_LIST_KEY="${BASE_DIR%:}list" + PROFILE_SLUG="${PROFILE_SLUG}" - # Note -- ${BASE_DIR%s} is a workaround to avoid doing additional conditional testing for existing profiles - # if terminal is set to gnome-terminal - : ${DEFAULT_SLUG:="$(${DCONF} read ${BASE_DIR%:}default | tr -d \')"} + # Note -- ${BASE_DIR%s} is a workaround to avoid doing additional conditional testing for existing profiles + # if terminal is set to gnome-terminal + : ${DEFAULT_SLUG:="$(${DCONF} read ${BASE_DIR%:}default | tr -d \')"} - LEFT_WRAPPER="[" - RIGHT_WRAPPER="]" - PALETTE_DELIM="', '" + LEFT_WRAPPER="[" + RIGHT_WRAPPER="]" + PALETTE_DELIM="', '" - apply_gtk - else - BASE_DIR="/apps/gnome-terminal/profiles/" - PROFILE_LIST_KEY="${BASE_DIR/profiles/global}profile_list" - LEGACY_BOLD=true + apply_gtk + else + BASE_DIR="/apps/gnome-terminal/profiles/" + PROFILE_LIST_KEY="${BASE_DIR/profiles/global}profile_list" + LEGACY_BOLD=true - : ${DEFAULT_SLUG:="$(${GCONF} read ${BASE_DIR}default_profile)"} + : ${DEFAULT_SLUG:="$(${GCONF} read ${BASE_DIR}default_profile)"} - apply_gtk legacy - fi - ;; + apply_gtk legacy + fi + ;; - mate-terminal ) - BASE_DIR="/org/mate/terminal/profiles/" - PROFILE_LIST_KEY="${BASE_DIR/profiles/global}profile-list" - LEGACY_BOLD=true +mate-terminal ) + BASE_DIR="/org/mate/terminal/profiles/" + PROFILE_LIST_KEY="${BASE_DIR/profiles/global}profile-list" + LEGACY_BOLD=true - : ${DEFAULT_SLUG:="$(${DCONF} read ${BASE_DIR/profiles/global}default-profile | tr -d \')"} + : ${DEFAULT_SLUG:="$(${DCONF} read ${BASE_DIR/profiles/global}default-profile | tr -d \')"} - PALETTE_DELIM=":" + PALETTE_DELIM=":" - apply_gtk - ;; + apply_gtk + ;; - tilix ) - BASE_DIR="/com/gexperts/Tilix/profiles/" - PROFILE_LIST_KEY="${BASE_DIR}list" +tilix ) + BASE_DIR="/com/gexperts/Tilix/profiles/" + PROFILE_LIST_KEY="${BASE_DIR}list" - : ${DEFAULT_SLUG:="$(${DCONF} read ${BASE_DIR}default | tr -d \')"} + : ${DEFAULT_SLUG:="$(${DCONF} read ${BASE_DIR}default | tr -d \')"} - LEFT_WRAPPER="[" - RIGHT_WRAPPER="]" - PALETTE_DELIM="', '" + LEFT_WRAPPER="[" + RIGHT_WRAPPER="]" + PALETTE_DELIM="', '" - appy_tilixschemes - apply_gtk - ;; + appy_tilixschemes + apply_gtk + ;; - xfce4-terminal ) - apply_xfce4-terminal - ;; +xfce4-terminal ) + apply_xfce4-terminal + ;; - * ) - printf '%s\n' \ - "Unsupported terminal!" \ - "" \ - "Supported terminals:" \ - " mintty and deriviates" \ - " guake" \ - " iTerm2" \ - " elementary terminal (pantheon/elementary)" \ - " mate-terminal" \ - " gnome-terminal" \ - " tilix" \ - " xfce4-terminal" \ - "" \ - "If you believe you have recieved this message in error," \ - "try manually setting \`TERMINAL', hint: ps -h -o comm -p \$PPID" - exit 1 - ;; +* ) + printf '%s\n' \ + "Unsupported terminal!" \ + "" \ + "Supported terminals:" \ + " mintty and deriviates" \ + " guake" \ + " iTerm2" \ + " elementary terminal (pantheon/elementary)" \ + " mate-terminal" \ + " gnome-terminal" \ + " tilix" \ + " xfce4-terminal" \ + "" \ + "If you believe you have recieved this message in error," \ + "try manually setting \`TERMINAL', hint: ps -h -o comm -p \$PPID" + exit 1 + ;; esac diff --git a/audio/noise-cancel.sh b/audio/noise-cancel.sh index a9fd86c..6feea85 100755 --- a/audio/noise-cancel.sh +++ b/audio/noise-cancel.sh @@ -1,6 +1,7 @@ # Microphone Realtime background noise reduction script # author Luigi Maselli - https://grigio.org licence: AS-IS -# credits: http://askubuntu.com/questions/18958/realtime-noise-removal-with-pulseaudio +# credits: +# http://askubuntu.com/questions/18958/realtime-noise-removal-with-pulseaudio # run as: sudo && pulseaudio -k sudo cp /etc/pulse/default.pa /etc/pulse/default.pa.bak @@ -8,4 +9,4 @@ sudo cat <> /etc/pulse/default.pa load-module module-echo-cancel source_name=noechosource sink_name=noechosink set-default-source noechosource set-default-sink noechosink -EOT \ No newline at end of file +EOT diff --git a/i3/detached.sh b/i3/detached.sh index 6b569ac..6759ef5 100755 --- a/i3/detached.sh +++ b/i3/detached.sh @@ -1,3 +1,10 @@ #!/bin/sh -xrandr --output DP-2-1 --off --output DP-2-2 --off --output DP-2-3 --off --output eDP-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal --output HDMI-2 --off --output HDMI-1 --off --output DP-2 --off --output DP-1 --off +xrandr \ +--output DP-2-1 --off \ +--output DP-2-2 --off \ +--output DP-2-3 --off \ +--output eDP-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal \ +--output HDMI-2 --off \ +--output HDMI-1 --off --output DP-2 --off --output DP-1 --off + echo "detached" > ~/.config/screenlayout/i3.current diff --git a/i3/home.sh b/i3/home.sh index 64a3659..1777381 100755 --- a/i3/home.sh +++ b/i3/home.sh @@ -1,3 +1,12 @@ #!/bin/sh -xrandr --output DP-2-1 --mode 1366x768 --pos 0x0 --rotate left --output DP-2-2 --mode 1920x1200 --pos 768x0 --rotate normal --output DP-2-3 --off --output eDP-1 --primary --mode 1920x1080 --pos 768x1200 --rotate normal --output HDMI-2 --off --output HDMI-1 --off --output DP-2 --off --output DP-1 --off +xrandr \ +--output DP-2-1 --mode 1366x768 --pos 0x0 --rotate left \ +--output DP-2-2 --mode 1920x1200 --pos 768x0 --rotate normal \ +--output DP-2-3 --off \ +--output eDP-1 --primary --mode 1920x1080 --pos 768x1200 --rotate normal \ +--output HDMI-2 --off \ +--output HDMI-1 --off \ +--output DP-2 --off \ +--output DP-1 --off + echo "home" > ~/.config/screenlayout/i3.current diff --git a/i3/i3move.sh b/i3/i3move.sh index 43e6873..d3e90b8 100755 --- a/i3/i3move.sh +++ b/i3/i3move.sh @@ -4,25 +4,25 @@ LAYOUT=`cat ~/.config/screenlayout/i3.current` MIDDLE="eDP-1" if [[ $LAYOUT == 'home' ]]; then - RIGHT="DP-2-2" - LEFT="DP-2-1" + RIGHT="DP-2-2" + LEFT="DP-2-1" elif [[ $LAYOUT == 'work' ]]; then - RIGHT="DP-2-2" - LEFT="DP-2-1" + RIGHT="DP-2-2" + LEFT="DP-2-1" elif [[ $LAYOUT == '3' ]]; then - MIDDLE="DP-2-2" - LEFT="DP-2-1" - RIGHT="eDP-1" + MIDDLE="DP-2-2" + LEFT="DP-2-1" + RIGHT="eDP-1" else - echo "No external displays connected" + echo "No external displays connected" fi if [[ $1 == 'right' ]]; then - i3 move workspace to output $RIGHT + i3 move workspace to output $RIGHT elif [[ $1 == 'middle' ]]; then - i3 move workspace to output $MIDDLE + i3 move workspace to output $MIDDLE elif [[ $1 == 'left' ]]; then - i3 move workspace to output $LEFT + i3 move workspace to output $LEFT else - echo "Invalid direction. Requires either 'up', 'left', or 'middle'" + echo "Invalid direction. Requires either 'up', 'left', or 'middle'" fi diff --git a/i3/work.sh b/i3/work.sh index cdf7bbb..7d060bf 100755 --- a/i3/work.sh +++ b/i3/work.sh @@ -1,3 +1,12 @@ #!/bin/sh -xrandr --output DP-2-1 --mode 1920x1080 --pos 0x0 --rotate left --output DP-2-2 --mode 1920x1080 --pos 1080x0 --rotate normal --output DP-2-3 --off --output eDP-1 --primary --mode 1920x1080 --pos 1080x1080 --rotate normal --output HDMI-2 --off --output HDMI-1 --off --output DP-2 --off --output DP-1 --off +xrandr \ +--output DP-2-1 --mode 1920x1080 --pos 0x0 --rotate left \ +--output DP-2-2 --mode 1920x1080 --pos 1080x0 --rotate normal \ +--output DP-2-3 --off \ +--output eDP-1 --primary --mode 1920x1080 --pos 1080x1080 --rotate normal \ +--output HDMI-2 --off \ +--output HDMI-1 --off \ +--output DP-2 --off \ +--output DP-1 --off + echo "work" > ~/.config/screenlayout/i3.current diff --git a/rofi/drun.sh b/rofi/drun.sh index afd9659..616818d 100755 --- a/rofi/drun.sh +++ b/rofi/drun.sh @@ -4,7 +4,7 @@ ROFI=$(pgrep -c rofi | cut -b 1) echo $ROFI if [[ "$ROFI" -eq "0" ]]; then - rofi -config /home/jpm/.config/rofi/config -show drun + rofi -config /home/jpm/.config/rofi/config -show drun else - killall rofi 2&>1 /dev/null + killall rofi 2&>1 /dev/null fi diff --git a/rofi/rofi-openvpn.sh b/rofi/rofi-openvpn.sh index 7cf8db3..d83eaf4 100755 --- a/rofi/rofi-openvpn.sh +++ b/rofi/rofi-openvpn.sh @@ -5,25 +5,25 @@ res=$(echo "Connection|John.Me.tz|MailCleaner|Disconnect|Restart" | rofi -sep "|" -dmenu -i -p 'P ' "" -columns 9 -width 45 -l 1 -config /home/jpm/.config/rofi/config -hide-scrollbar -eh 1 -location 0 -auto-select -no-fullscreen) if [ $res = "Connection" ]; then - /usr/bin/uxterm -e 'sudo /usr/bin/nmtui' + /usr/bin/uxterm -e 'sudo /usr/bin/nmtui' elif [ $res = "John.Me.tz" ]; then - sudo /usr/bin/systemctl stop openvpn-client@mailcleaner - sudo /usr/bin/systemctl restart wg-quick@wg0 -elif [ $res = "MailCleaner" ]; then - sudo /usr/bin/systemctl stop wg-quick@wg0 - sudo /usr/bin/systemctl restart openvpn-client@mailcleaner -elif [ $res = "Disconnect" ]; then - sudo /usr/bin/systemctl stop openvpn-client@mailcleaner - sudo /usr/bin/systemctl stop wg-quick@wg0 -elif [ $res = "Restart" ]; then - if [ "`ip addr show wg0 2> /dev/null`" != "" ]; then + sudo /usr/bin/systemctl stop openvpn-client@mailcleaner sudo /usr/bin/systemctl restart wg-quick@wg0 - fi - if [ "`ip addr show tun0 2> /dev/null`" != "" ]; then +elif [ $res = "MailCleaner" ]; then + sudo /usr/bin/systemctl stop wg-quick@wg0 sudo /usr/bin/systemctl restart openvpn-client@mailcleaner - fi +elif [ $res = "Disconnect" ]; then + sudo /usr/bin/systemctl stop openvpn-client@mailcleaner + sudo /usr/bin/systemctl stop wg-quick@wg0 +elif [ $res = "Restart" ]; then + if [ "`ip addr show wg0 2> /dev/null`" != "" ]; then + sudo /usr/bin/systemctl restart wg-quick@wg0 + fi + if [ "`ip addr show tun0 2> /dev/null`" != "" ]; then + sudo /usr/bin/systemctl restart openvpn-client@mailcleaner + fi else - exit + exit fi # Waybar sometimes doesn't update with the VPN IP, for whatever reason. Restart it. diff --git a/rofi/rofi-power-menu.sh b/rofi/rofi-power-menu.sh index 12fdcdd..1af68dc 100755 --- a/rofi/rofi-power-menu.sh +++ b/rofi/rofi-power-menu.sh @@ -4,39 +4,39 @@ # Determine if Sway or i3 if [ -z ${SWAYSOCK+x} ]; then - WM="i3" + WM="i3" else - WM="sway" + WM="sway" fi if [[ $WM == 'i3' ]]; then - res=$(printf "🔒 Lock|↩ Logout|↻ Reload i3|↹ Restart i3|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -columns 1 -rows 7 -width 32 -l 1 -hide-scrollbar -eh 1 -location 0 -padding 12 -opacity 100 -auto-select -no-fullscreen) + res=$(printf "🔒 Lock|↩ Logout|↻ Reload i3|↹ Restart i3|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -columns 1 -rows 7 -width 32 -l 1 -hide-scrollbar -eh 1 -location 0 -padding 12 -opacity 100 -auto-select -no-fullscreen) else - res=$(echo "🔒 Lock|↩ Logout|↻ Reload Sway|↻ Reload Waybar|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -no-lazy-grab -auto-select -no-fullscreen) + res=$(echo "🔒 Lock|↩ Logout|↻ Reload Sway|↻ Reload Waybar|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -no-lazy-grab -auto-select -no-fullscreen) fi if [ "$res" == "🔒 Lock" ]; then - ${WM}lock -c 323232 + ${WM}lock -c 323232 elif [ "$res" == "↩ Logout" ]; then - # Prevent auto-login - rm /home/jpm/.config/last_login_gui - ${WM} exit + # Prevent auto-login + rm /home/jpm/.config/last_login_gui + ${WM} exit elif [ "$res" == "↻ Reload i3" ]; then - i3 reload + i3 reload elif [ "$res" == "↹ Restart i3" ]; then - i3 restart + i3 restart elif [ "$res" == "↻ Reload Sway" ]; then - sway reload + sway reload elif [ "$res" == "↻ Reload Waybar" ]; then - # Need to integrate with sway/displays.pl for alternative outputs - /home/jpm/scripts/sway/displays.pl -w + # Need to integrate with sway/displays.pl for alternative outputs + /home/jpm/scripts/sway/displays.pl -w elif [ "$res" == "🡙 Reboot" ]; then - rm $SSH_AUTH_SOCK - sudo systemctl reboot -i + rm $SSH_AUTH_SOCK + sudo systemctl reboot -i elif [ "$res" == "⏻ Shutdown" ]; then - rm $SSH_AUTH_SOCK - sudo systemctl poweroff -i + rm $SSH_AUTH_SOCK + sudo systemctl poweroff -i elif [ "$res" == "↯ Hibernate" ]; then - sudo systemctl hibernate -i + sudo systemctl hibernate -i fi exit 0 diff --git a/rofi/rofi-send-to-kodi.sh b/rofi/rofi-send-to-kodi.sh index 735b552..9b3bd1e 100755 --- a/rofi/rofi-send-to-kodi.sh +++ b/rofi/rofi-send-to-kodi.sh @@ -1,5 +1,6 @@ #!/bin/bash -INPUT="$(rofi -dmenu -i -p 'Kodi:' "" -columns 1 -rows 7 -width 32 -l 1 -hide-scrollbar -eh 1 -location 0 -padding 12 -opacity 100)" +INPUT="$(rofi -dmenu -i -p 'Kodi:' "" -columns 1 -rows 7 -width 32 -l 1 \ + -hide-scrollbar -eh 1 -location 0 -padding 12 -opacity 100)" /home/jpm/scripts/send-to-kodi.sh $INPUT 2>&1 /dev/null diff --git a/rofi/rofi-ssh-menu.sh b/rofi/rofi-ssh-menu.sh index c46ce99..1e06f14 100755 --- a/rofi/rofi-ssh-menu.sh +++ b/rofi/rofi-ssh-menu.sh @@ -1,28 +1,33 @@ #!/bin/bash -res=$(echo "john.me.tz|root@john.me.tz|t470s.lan.john.me.tz|shb.ng|kipary.mailcleaner.net|media.lan.john.me.tz|pipcam.lan.john.me.tz|therm.lan.john.me.tz|hud.lan.john.me.tz|vm.lan.john.me.tz" | rofi -sep "|" -dmenu -i -p 'P ' "" -columns 1 -rows 1 -width 45 -l 1 -config /home/jpm/.config/rofi/config -hide-scrollbar -eh 1 -location 0 -yoffset 0 -padding 12 -opacity 100 -auto-select -no-fullscreen) +res=$(echo "john.me.tz|root@john.me.tz|t470s.lan.john.me.tz|shb.ng|\ +kipary.mailcleaner.net|media.lan.john.me.tz|pipcam.lan.john.me.tz|\ +therm.lan.john.me.tz|hud.lan.john.me.tz|vm.lan.john.me.tz" | \ +rofi -sep "|" -dmenu -i -p 'P ' "" -columns 1 -rows 1 -width 45 -l 1 -config \ +/home/jpm/.config/rofi/config -hide-scrollbar -eh 1 -location 0 -yoffset 0 \ +-padding 12 -opacity 100 -auto-select -no-fullscreen) if [ $res = "john.me.tz" ]; then - /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs w' + /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs w' elif [ $res = "root@john.me.tz" ]; then - /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs r' + /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs r' elif [ $res = "shb.ng" ]; then - /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs s' + /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs s' elif [ $res = "kipary.mailcleaner.net" ]; then - /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs d' + /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs d' elif [ $res = "camera.lan.john.me.tz" ]; then - /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs c' + /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs c' elif [ $res = "hud.lan.john.me.tz" ]; then - /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs h' + /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs h' elif [ $res = "media.lan.john.me.tz" ]; then - /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs m' + /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs m' elif [ $res = "programmer.lan.john.me.tz" ]; then - /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs p' + /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs p' elif [ $res = "t470s.lan.john.me.tz" ]; then - /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs l' + /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs l' elif [ $res = "therm.lan.john.me.tz" ]; then - /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs t' + /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs t' elif [ $res = "vm.lan.john.me.tz" ]; then - /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs v' + /usr/bin/urxvt -e /bin/bash -c '/home/jpm/scripts/sshs v' fi exit 0 diff --git a/rofi/sway-alt-tab.sh b/rofi/sway-alt-tab.sh index 032500e..bc1f56b 100755 --- a/rofi/sway-alt-tab.sh +++ b/rofi/sway-alt-tab.sh @@ -9,10 +9,10 @@ sed -e 's/^\([0-9]*\)\t*\(.*\)/\2 \1/' | rofi -dmenu -config ~/.config/rofi/sidebar.rasi | { -read -r + read -r -id=`echo $REPLY | rev | cut -d' ' -f1 | rev` + id=`echo $REPLY | rev | cut -d' ' -f1 | rev` -swaymsg "[con_id=$id]" focus + swaymsg "[con_id=$id]" focus } diff --git a/send-to-kodi.sh b/send-to-kodi.sh index 9b41bac..e538f01 100755 --- a/send-to-kodi.sh +++ b/send-to-kodi.sh @@ -14,7 +14,7 @@ local_port=12345 show_help() { - cat</dev/null; then - zenity --error --ellipsize --text "$*" - else - echo "$*" 1>&2 - fi + if type zenity &>/dev/null; then + zenity --error --ellipsize --text "$*" + else + echo "$*" 1>&2 + fi - exit 1 + exit 1 } send_json() { - curl \ - ${user:+--user "$user:$pass"} \ - -X POST \ - -H "Content-Type: application/json" \ - -d '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"'"$1"'"}},"id":1}' \ - http://$host:$port/jsonrpc \ - || error "Failed to send link - is Kodi running?" + curl \ + ${user:+--user "$user:$pass"} \ + -X POST \ + -H "Content-Type: application/json" \ + -d '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"'"$1"'"}},"id":1}' \ + http://$host:$port/jsonrpc \ + || error "Failed to send link - is Kodi running?" } ytplugin='plugin://plugin.video.youtube/?action=play_video&videoid=' @@ -61,30 +61,35 @@ ytplugin='plugin://plugin.video.youtube/?action=play_video&videoid=' # Dialog box? input=$1 until [[ $input ]]; do - input="$(zenity --entry --title "Send to Kodi" --text "Paste a video link here")" || exit + input="$(zenity --entry --title "Send to Kodi" --text \ + "Paste a video link here")" || exit done if [[ $input =~ ^file:// ]]; then - # Remove file:// and carrige return (\r) at the end - input="$(sed 's%^file://%%;s/\r$//' <<< "$input")" + # Remove file:// and carrige return (\r) at the end + input="$(sed 's%^file://%%;s/\r$//' <<< "$input")" fi # Get URL for... # Local media if [[ -e $input ]]; then - type nc &>/dev/null || error "netcat required" - [[ $local_hostname && $local_port ]] || error "Please set local hostname and port in configuration" + type nc &>/dev/null || error "netcat required" + [[ $local_hostname && $local_port ]] || \ + error "Please set local hostname and port in configuration" - # Start netcat in background and kill it when we exit - nc -lp $local_port < "$input" & - trap "kill $!" EXIT + # Start netcat in background and kill it when we exit + nc -lp $local_port < "$input" & + trap "kill $!" EXIT - url="tcp://$local_hostname:$local_port" + url="tcp://$local_hostname:$local_port" # youtube.com / youtu.be elif [[ $input =~ ^https?://(www\.)?youtu(\.be/|be\.com/watch\?v=) ]]; then - url="$ytplugin$(sed 's/.*\(youtu\.be\/\|[&?]v=\)\([a-zA-Z0-9_-]\+\).*/\2/' <<< "$input")" + url="$ytplugin$(\ + sed 's/.*\(youtu\.be\/\|[&?]v=\)\([a-zA-Z0-9_-]\+\).*/\2/'\ + <<< "$input"\ + )" # Playable formats elif [[ $input =~ \.(mp4|mkv|mov|avi|flv|wmv|asf|mp3|flac|mka|m4a|aac|ogg|pls|jpg|png|gif|jpeg|tiff)(\?.*)?$ ]]; then @@ -92,8 +97,9 @@ elif [[ $input =~ \.(mp4|mkv|mov|avi|flv|wmv|asf|mp3|flac|mka|m4a|aac|ogg|pls|jp # Youtube-dl else - type youtube-dl &>/dev/null || error "youtube-dl required" - url="$(youtube-dl -gf best "$input")" || error "No videos found, or site not supported by youtube-dl" + type youtube-dl &>/dev/null || error "youtube-dl required" + url="$(youtube-dl -gf best "$input")" || \ + error "No videos found, or site not supported by youtube-dl" fi [[ $url ]] && send_json "$url" diff --git a/sway/displays.pl b/sway/displays.pl index 8d9d3c4..7ddc06f 100755 --- a/sway/displays.pl +++ b/sway/displays.pl @@ -45,10 +45,10 @@ my $last = "$ENV{'HOME'}/.config/last_display"; # $ swaymsg -t get_outputs # Output eDP-1 'Unknown 0x057D *0x00000000*' my %outputs = ( - '0x00000101' => 'Sam', - '3CQ4342S6W' => 'HP-1', - '3CQ3310Q1Q' => 'HP-2', - '0x00000000' => 'LVDS' + '0x00000101' => 'Sam', + '3CQ4342S6W' => 'HP-1', + '3CQ3310Q1Q' => 'HP-2', + '0x00000000' => 'LVDS' ); ######################################################################## @@ -59,90 +59,90 @@ my %outputs = ( # Second-level keys are the display friendly-names, above # Third-level are the actual settings for that display my %configs = ( - 'detached' => { - 'HP-1' => { - 'on' => 0 + 'detached' => { + 'HP-1' => { + 'on' => 0 + }, + 'HP-2' => { + 'on' => 0 + }, + 'Sam' => { + 'on' => 0 + }, + 'LVDS' => { + 'on' => 1, + 'width' => 1920, + 'height' => 1080, + 'x' => 0, + 'y' => 0, + 'rotate' => 0, + 'waybar' => 'bottom' + } }, - 'HP-2' => { - 'on' => 0 + 'stacked' => { + 'Sam' => { + 'on' => 1, + 'width' => 1920, + 'height' => 1080, + 'x' => 960, + 'y' => 0, + 'rotate' => 0, + 'waybar' => 'bottom' + }, + 'HP-1' => { + 'on' => 1, + 'width' => 1920, + 'height' => 1080, + 'x' => 0, + 'y' => 1200, + 'rotate' => 0, + 'waybar' => 'top' + }, + 'HP-2' => { + 'on' => 1, + 'width' => 1920, + 'height' => 1080, + 'x' => 1920, + 'y' => 1200, + 'rotate' => 0, + 'waybar' => 'top' + }, + 'LVDS' => { + 'on' => 0 + } }, - 'Sam' => { - 'on' => 0 - }, - 'LVDS' => { - 'on' => 1, - 'width' => 1920, - 'height' => 1080, - 'x' => 0, - 'y' => 0, - 'rotate' => 0, - 'waybar' => 'bottom' + 'sidebyside' => { + 'HP-1' => { + 'on' => 1, + 'width' => 1080, + 'height' => 1920, + 'x' => 0, + 'y' => 225, + 'rotate' => 270, + 'waybar' => 'top' + }, + 'Sam' => { + 'on' => 1, + 'width' => 1200, + 'height' => 1920, + 'x' => 1080, + 'y' => 0, + 'rotate' => 90, + 'waybar' => 'top' + }, + 'HP-2' => { + 'on' => 1, + 'width' => 1080, + 'height' => 1920, + 'x' => 2280, + 'y' => 225, + 'rotate' => 90, + 'waybar' => 'top' + }, + 'LVDS' => { + 'on' => 0, + } } - }, - 'stacked' => { - 'Sam' => { - 'on' => 1, - 'width' => 1920, - 'height' => 1080, - 'x' => 960, - 'y' => 0, - 'rotate' => 0, - 'waybar' => 'bottom' - }, - 'HP-1' => { - 'on' => 1, - 'width' => 1920, - 'height' => 1080, - 'x' => 0, - 'y' => 1200, - 'rotate' => 0, - 'waybar' => 'top' - }, - 'HP-2' => { - 'on' => 1, - 'width' => 1920, - 'height' => 1080, - 'x' => 1920, - 'y' => 1200, - 'rotate' => 0, - 'waybar' => 'top' - }, - 'LVDS' => { - 'on' => 0 - } - }, - 'sidebyside' => { - 'HP-1' => { - 'on' => 1, - 'width' => 1080, - 'height' => 1920, - 'x' => 0, - 'y' => 225, - 'rotate' => 270, - 'waybar' => 'top' - }, - 'Sam' => { - 'on' => 1, - 'width' => 1200, - 'height' => 1920, - 'x' => 1080, - 'y' => 0, - 'rotate' => 90, - 'waybar' => 'top' - }, - 'HP-2' => { - 'on' => 1, - 'width' => 1080, - 'height' => 1920, - 'x' => 2280, - 'y' => 225, - 'rotate' => 90, - 'waybar' => 'top' - }, - 'LVDS' => { - 'on' => 0, - } - } ); ######################################################################## @@ -156,34 +156,37 @@ my $waybar_only = 0; my $config; if (scalar(@ARGV)) { - while (@ARGV) { - my $arg = shift; - if ($arg eq "-w") { - $waybar_only = 1; - } else { - if (defined $config) { - die "Too many arguments.\n"; - } - $config = $arg; + while (@ARGV) { + my $arg = shift; + if ($arg eq "-w") { + $waybar_only = 1; + } else { + if (defined $config) { + die "Too many arguments.\n"; + } + $config = $arg; + } } - } } # Get previous config if one is not provided unless (defined $config) { - open(my $fh, '<', $last) || die "Config name not provided and failed to open $last\n"; - $config = <$fh>; - close($fh); - chomp $config; + open(my $fh, '<', $last) || + die "Config name not provided and failed to open $last\n"; + $config = <$fh>; + close($fh); + chomp $config; } # Bail if requested config doesn't exist unless (defined $configs{$config}) { - die "$config is not a defined configuration: " . join(', ', keys %configs) . "\n"; + die "$config is not a defined configuration: " + . join(', ', keys %configs) . "\n"; } # Write config that is to be used so that it can be recovered as default -open(my $fh, '>', $last) || print STDERR "Config name cannot be written to $last\n"; +open(my $fh, '>', $last) || + print STDERR "Config name cannot be written to $last\n"; print $fh $config; close($fh); @@ -199,72 +202,77 @@ my $on; my @off; for (my $i = 0; $i < scalar(@$displays); $i++) { - # If a display is found without any settings, print error and turn it off - unless (defined $configs{$config}{$outputs{$displays->[$i]->{serial}}}) { - print STDERR "Output $displays->[$i]->{name} ($displays->[$i]->{serial}) found without defined function. Disabling.\n"; - push @off, $displays->[$i]->{name}; - next; - } + # If a display is found without any settings print error and turn it off + unless (defined $configs{$config}{$outputs{$displays->[$i]->{serial}}}){ + print STDERR "Output $displays->[$i]->{name} (" + . $displays->[$i]->{serial} + . ") found without defined function. Disabling.\n"; + push @off, $displays->[$i]->{name}; + next; + } - # If display is enabled, copy all of the desired settings - if ($configs{$config}{$outputs{$displays->[$i]->{serial}}}{on}) { - $on->{$outputs{$displays->[$i]->{serial}}} = $configs{$config}{$outputs{$displays->[$i]->{serial}}}; - $on->{$outputs{$displays->[$i]->{serial}}}{output} = $displays->[$i]->{name}; - # Otherwise simply list it for disabling - } else { - push @off, $displays->[$i]->{name}; - } + # If display is enabled, copy all of the desired settings + if ($configs{$config}{$outputs{$displays->[$i]->{serial}}}{on}) { + $on->{$outputs{$displays->[$i]->{serial}}} = + $configs{$config}{$outputs{$displays->[$i]->{serial}}}; + $on->{$outputs{$displays->[$i]->{serial}}}{output} = + $displays->[$i]->{name}; + # Otherwise simply list it for disabling + } else { + push @off, $displays->[$i]->{name}; + } } # Skip enabling/disabling displays if only running waybar (re)start unless ($waybar_only) { - # Number of simultaneous outputs is limited by gpu, so disabled displays first - foreach (@off) { + # Number of simultaneous outputs is limited by gpu, so disabled displays + # first + foreach (@off) { - # Sway returns status as JSON - my $res_raw = `sway output $_ disable`; - my $res = $json->decode($res_raw)->[0]; + # Sway returns status as JSON + my $res_raw = `sway output $_ disable`; + my $res = $json->decode($res_raw)->[0]; + + # If failed, print to STDERR + unless ($res->{success}) { + print STDERR "Error ($res->{error}) in command 'sway" + . "output $_ disable'\n"; + } - # If failed, print to STDERR - unless ($res->{success}) { - print STDERR "Error ($res->{error}) in command 'sway output $_ disable'\n"; } - - } } # Kill existing Waybars require Proc::ProcessTable; my $t = new Proc::ProcessTable; foreach my $p ( @{ $t->table } ) { - my $cmndline = $p->{'cmndline'}; - $cmndline =~ s/\s*$//g; - if ($cmndline =~ /^waybar.*/) { - # Never kill this process - if ($p->{'pid'} == $$) { - next; - # SIGKILL match - # TODO BUG: when multiple processes are running, some respawn with new PIDs. IDK why? - } else { - $p->kill(9); + my $cmndline = $p->{'cmndline'}; + $cmndline =~ s/\s*$//g; + if ($cmndline =~ /^waybar.*/) { + # Never kill this process + if ($p->{'pid'} == $$) { + next; + } else { + $p->kill(9); + } } - } } # Load in config template my $template; if (open (my $fh, '<', $waybar_template)) { - while (<$fh>) { - $template .= $_; - } - close $fh; - chomp $template; + while (<$fh>) { + $template .= $_; + } + close $fh; + chomp $template; } else { - print STDERR "Failed to load template $waybar_template\n"; + print STDERR "Failed to load template $waybar_template\n"; } -# If template is already set up as an array, remove the square brackets so that we can concatenate multiple displays +# If template is already set up as an array, remove the square brackets so that +# we can concatenate multiple displays $template =~ s/^[^\[\{]*\[(.*)\]$/$1/s; # Setup waybar config file @@ -273,52 +281,57 @@ my $waybar = ''; # Configure each enabled display foreach my $out (keys %$on) { - unless ($waybar_only) { - # Build command, starting by enabling and powering on - my $cmd = "sway output $on->{$out}->{output} enable dpms on"; + unless ($waybar_only) { + # Build command, starting by enabling and powering on + my $cmd = "sway output $on->{$out}->{output} enable dpms on"; - # If additional options are provided, add them to command - if (defined $on->{$out}->{rotate}) { - $cmd .= " transform $on->{$out}->{rotate}"; - } - if (defined $on->{$out}->{x} && defined $on->{$out}->{y}) { - $cmd .= " position $on->{$out}->{x} $on->{$out}->{y}"; - } - if (defined $on->{$out}->{width} && defined $on->{$out}->{height}) { - $cmd .= " mode $on->{$out}->{width}x$on->{$out}->{height}"; + # If additional options are provided, add them to command + if (defined $on->{$out}->{rotate}) { + $cmd .= " transform $on->{$out}->{rotate}"; + } + if (defined $on->{$out}->{x} && defined $on->{$out}->{y}) { + $cmd .= " position $on->{$out}->{x} $on->{$out}->{y}"; + } + if (defined $on->{$out}->{width} && + defined $on->{$out}->{height} ) + { + $cmd .= " mode $on->{$out}->{width}x$on->{$out}->{height}"; + } + + # Sway returns status as JSON + my $res_raw = `$cmd`; + my $res = $json->decode($res_raw)->[0]; + + # If failed, print to STDERR + unless ($res->{success}) { + print STDERR "Error ($res->{error}) in command '$cmd'\n"; + } } - # Sway returns status as JSON - my $res_raw = `$cmd`; - my $res = $json->decode($res_raw)->[0]; + # Skip waybar setup if template failed to be loaded + if ( (defined $template) && + (defined $on->{$out}->{waybar}) && + ($on->{$out}->{waybar} =~ m/(top|bottom|left|right)/) ) + { + + # If there's already a display set up, add a comma + unless ($waybar eq '') { + $waybar .= ','; + } + + $waybar .= $template; + + # Replace basic preferences + $waybar =~ s/__OUTPUT__/"$on->{$out}->{output}"/; + $waybar =~ s/__POSITION__/"$on->{$out}->{waybar}"/; + if (defined $on->{$out}->{width}) { + $waybar =~ s/__WIDTH__/$on->{$out}->{width}/; + # If width is not set, comment that line out to use default + } else { + $waybar =~ s/([^\s]*\s*)__WIDTH__/\/\/ $1__WIDTH__/gg; + } - # If failed, print to STDERR - unless ($res->{success}) { - print STDERR "Error ($res->{error}) in command '$cmd'\n"; } - } - - # Skip waybar setup if template failed to be loaded - if ( (defined $template) && (defined $on->{$out}->{waybar}) && ($on->{$out}->{waybar} =~ m/(top|bottom|left|right)/) ) { - - # If there's already a display set up, add a comma - unless ($waybar eq '') { - $waybar .= ','; - } - - $waybar .= $template; - - # Replace basic preferences - $waybar =~ s/__OUTPUT__/"$on->{$out}->{output}"/; - $waybar =~ s/__POSITION__/"$on->{$out}->{waybar}"/; - if (defined $on->{$out}->{width}) { - $waybar =~ s/__WIDTH__/$on->{$out}->{width}/; - # If width is not set, comment that line out to use default - } else { - $waybar =~ s/([^\s]*\s*)__WIDTH__/\/\/ $1__WIDTH__/gg; - } - - } } # Restore array formatting @@ -327,16 +340,16 @@ $waybar = '[' . $waybar . ']'; # Start Waybar as fork my $pid = fork; unless ($pid) { - open STDIN, '/dev/null'; - open STDOUT, '>>/dev/null'; - open STDERR, '>>/dev/null'; - # Write config to a temporary file - my $tmp = $waybar_temporary . "/waybar-" . time() .".config"; - open ($fh, '>', $tmp); - print $fh $waybar; - close $fh; - `nohup waybar --config=$tmp`; + open STDIN, '/dev/null'; + open STDOUT, '>>/dev/null'; + open STDERR, '>>/dev/null'; + # Write config to a temporary file + my $tmp = $waybar_temporary . "/waybar-" . time() .".config"; + open ($fh, '>', $tmp); + print $fh $waybar; + close $fh; + `nohup waybar --config=$tmp`; - # Remove config - unlink $tmp; + # Remove config + unlink $tmp; } diff --git a/sway/gammastep.pl b/sway/gammastep.pl index 3d71179..cc252c5 100755 --- a/sway/gammastep.pl +++ b/sway/gammastep.pl @@ -16,27 +16,28 @@ my $lat_lon = fetch_lat_lon($ua, $json, $location); my $pid = fork; unless ($pid) { - open STDIN, '/dev/null'; - open STDOUT, '>>/dev/null'; - open STDERR, '>>/dev/null'; + open STDIN, '/dev/null'; + open STDOUT, '>>/dev/null'; + open STDERR, '>>/dev/null'; - `gammastep -l $lat_lon`; + `gammastep -l $lat_lon`; } -sub fetch_lat_lon { - my ($ua, $json, $location) = @_; +sub fetch_lat_lon +{ + my ($ua, $json, $location) = @_; + + my $raw = $ua->get($location)->content(); + if (defined $raw) { + my $decoded = $json->decode($raw); + if (defined $decoded->{lat} && defined $decoded->{lon}) { + return "$decoded->{lat}:$decoded->{lon}"; + } + print $decoded->{lat}; - my $raw = $ua->get($location)->content(); - if (defined $raw) { - my $decoded = $json->decode($raw); - if (defined $decoded->{lat} && defined $decoded->{lon}) { - return "$decoded->{lat}:$decoded->{lon}"; } - print $decoded->{lat}; - - } - sleep 5; - return fetch_lat_lon($ua, $json, $location); + sleep 5; + return fetch_lat_lon($ua, $json, $location); } exit; diff --git a/sway/popup-term.pl b/sway/popup-term.pl index 50eaae8..5e70e4f 100755 --- a/sway/popup-term.pl +++ b/sway/popup-term.pl @@ -19,57 +19,61 @@ my $root = $json->decode($raw); my $display = $root->{focus}->[0]; my ($workspace, $term_id, $term_ws); foreach my $d (@{$root->{nodes}}) { - # If both the current workspace and terminal have been found, nothing else to look for - if (defined($workspace) && defined($term_id)) { - last; - # If the display from this iteration of the loop is in focus, look for the active workspace - } elsif ($d->{id} eq $display) { - foreach my $w (@{$d->{nodes}}) { - # Again, if both found, skip - if (defined($workspace) && defined($term_id)) { + # If both the current workspace and terminal have been found + # nothing else to look for + if (defined($workspace) && defined($term_id)) { last; - # Otherwise if the current workspace is active, mark it - } elsif ($w->{id} eq $d->{focus}->[0]) { - $workspace = $w->{name}; - } - # In any case, look for the terminal app - foreach my $n (@{$w->{floating_nodes}}) { - if ($n->{name} eq $term) { - $term_id = $n->{id}; - $term_ws = $w->{name}; - last; + # If the display from this iteration of the loop is in focus + # look for the active workspace + } elsif ($d->{id} eq $display) { + foreach my $w (@{$d->{nodes}}) { + # Again, if both found, skip + if (defined($workspace) && defined($term_id)) { + last; + # Otherwise if the current workspace is active, mark it + } elsif ($w->{id} eq $d->{focus}->[0]) { + $workspace = $w->{name}; + } + # In any case, look for the terminal app + foreach my $n (@{$w->{floating_nodes}}) { + if ($n->{name} eq $term) { + $term_id = $n->{id}; + $term_ws = $w->{name}; + last; + } + } } - } - } - # All other displays only need to be quickly searched for the term_id - } else { - foreach my $w (@{$d->{nodes}}) { - if (defined($term_id)) { - last; - } - foreach my $n (@{$w->{floating_nodes}}) { - if ($n->{name} eq $term) { - $term_id = $n->{id}; - $term_ws = $w->{name}; - last; + # All other displays only need to be quickly searched for the term_id + } else { + foreach my $w (@{$d->{nodes}}) { + if (defined($term_id)) { + last; + } + foreach my $n (@{$w->{floating_nodes}}) { + if ($n->{name} eq $term) { + $term_id = $n->{id}; + $term_ws = $w->{name}; + last; + } + } } - } } - } } -print "Active workspace = $workspace\nTerminal ID = $term_id\nTerminal WS = $term_ws\n"; +print "Active workspace = $workspace\n" + . "Terminal ID = $term_id\n" + . "Terminal WS = $term_ws\n"; # If there is no terminal found, spawn one if (!defined($term_id)) { - print "No term running, starting one\n"; - exec $term -# If the current workspace is known and terminal isn't on it, bring and give focus + print "No term running, starting one\n"; + exec $term +# If the current workspace is known and terminal isn't on it, bring and focus } elsif ($workspace != $term_ws) { - print "Term not on current workspace, bringing it\n"; - `swaymsg "[con_id=$term_id]" move workspace $workspace`; - `swaymsg "[con_id=$term_id]" focus`; + print "Term not on current workspace, bringing it\n"; + `swaymsg "[con_id=$term_id]" move workspace $workspace`; + `swaymsg "[con_id=$term_id]" focus`; # Otherwise hide it from whereever it is } else { - print "Term is on current workspace or lost, moving to $hidden\n"; - `swaymsg "[con_id=$term_id]" move workspace $hidden`; + print "Term is on current workspace or lost, moving to $hidden\n"; + `swaymsg "[con_id=$term_id]" move workspace $hidden`; } diff --git a/sway/swayidle.sh b/sway/swayidle.sh index 1b855e6..83d47da 100755 --- a/sway/swayidle.sh +++ b/sway/swayidle.sh @@ -3,30 +3,34 @@ BLFILE="/tmp/blc" if [ -z $1 ]; then - echo "Missing argument: swayidlerun, swayidlewarn, swayidlesleep or swayidlewake" + echo "Missing argument: swayidlerun, swayidlewarn, swayidlesleep or" \ + " swayidlewake" elif [ $1 == "swayidlerun" ]; then - swayidle timeout 270 "/home/jpm/scripts/swayidle.sh swayidlewarn" before-sleep "/home/jpm/scripts/swayidle.sh swayidlesleep" resume "/home/jpm/scripts/swayidle.sh swayidlewake" + swayidle timeout 270 "/home/jpm/scripts/swayidle.sh swayidlewarn" \ + before-sleep "/home/jpm/scripts/swayidle.sh swayidlesleep" \ + resume "/home/jpm/scripts/swayidle.sh swayidlewake" elif [ $1 == "swayidlewarn" ]; then - # Store current brightness - echo $(/home/jpm/bin/blc.pl %) > $BLFILE - # Dim display - /home/jpm/bin/blc.pl = 1 - # Warning notifications - /home/jpm/scripts/swayidlecountdown.sh + # Store current brightness + echo $(/home/jpm/bin/blc.pl %) > $BLFILE + # Dim display + /home/jpm/bin/blc.pl = 1 + # Warning notifications + /home/jpm/scripts/swayidlecountdown.sh elif [ $1 == "swayidlesleep" ]; then - # Change nick to AFK - ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t 'screen -S irssi -X stuff "/nick jpmAFK^M"' - # Turn off monitor - swaymsg 'swaymsg "output * dpms off"' - # Lock screen - swaylock -c 323232 + # Change nick to AFK + ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \ + 'screen -S irssi -X stuff "/nick jpmAFK^M"' + # Turn off monitor + swaymsg 'swaymsg "output * dpms off"' + # Lock screen + swaylock -c 323232 elif [ $1 == "swayidlewake" ]; then - # Kill sleep if running - # Turn on monitor - swaymsg 'swaymsg "output * dpms on"' - # Restore brightness level - kill `pgrep swayidlecountdo` - /home/jpm/bin/blc.pl = $(cat /tmp/blc) + # Kill sleep if running + # Turn on monitor + swaymsg 'swaymsg "output * dpms on"' + # Restore brightness level + kill `pgrep swayidlecountdo` + /home/jpm/bin/blc.pl = $(cat /tmp/blc) else - echo "Invalid argument: run, sleep or wake" + echo "Invalid argument: run, sleep or wake" fi diff --git a/sway/swayidlecountdown.sh b/sway/swayidlecountdown.sh index 0c8574b..b2cef69 100755 --- a/sway/swayidlecountdown.sh +++ b/sway/swayidlecountdown.sh @@ -1,5 +1,5 @@ #!/bin/bash for i in `seq 0 30`; do - notify-send -t 999 "Sleeping" $(expr 30 - $i); sleep 1 + notify-send -t 999 "Sleeping" $(expr 30 - $i); sleep 1 done diff --git a/sway/toggle_outputs.sh b/sway/toggle_outputs.sh index 072718c..aae4255 100755 --- a/sway/toggle_outputs.sh +++ b/sway/toggle_outputs.sh @@ -3,7 +3,7 @@ CURRENT=`cat /home/jpm/.config/last_display` if [ "$CURRENT" == "detached" ]; then - /home/jpm/scripts/sway/displays.pl stacked + /home/jpm/scripts/sway/displays.pl stacked else - /home/jpm/scripts/sway/displays.pl detached + /home/jpm/scripts/sway/displays.pl detached fi diff --git a/thinkpad/blc.pl b/thinkpad/blc.pl index d9a4f0e..1183039 100755 --- a/thinkpad/blc.pl +++ b/thinkpad/blc.pl @@ -5,107 +5,117 @@ my $cur_file = "/sys/class/backlight/intel_backlight/brightness"; my $max_file = "/sys/class/backlight/intel_backlight/max_brightness"; my $last_file = "/home/jpm/.config/blc.last"; -sub to_percent { - my $value = shift; - if ($value eq "Permission Denied") { - return $value; - } else { - $value = int($value/get_max()*100); - return $value . '%'; - } -} - -sub get_offset { - return int(get_max()/100); -} - -sub get_current { - open(my $c,'<',"$cur_file"); - my $current = <$c>; - close $c; - chomp $current; - return $current; -} - -sub get_max { - open(my $m,'<',"$max_file"); - my $max = <$m>; - close $m; - chomp $max; - return $max; -} - -sub get_min { - return int((get_max()/100)+2); -} - -sub writable { - if (! -w $cur_file) { - return 0; - } else { - return 1; - } -} - -sub increment { - if (writable()) { - my $current = get_current(); - my $max = get_max(); - my $target = $current+get_offset(); - if ($target > $max) { - $target = $max; - } - open(my $c,'>',"$cur_file"); - print $c $target; - close $c; - return $target; - } else { - return "Permission Denied"; - } -} - -sub decrement { - if (writable()) { - my $current = get_current(); - my $min = get_min(); - my $target = $current-get_offset(); - if ($target < $min) { - $target = $min; - } - open(my $c,'>',"$cur_file"); - print $c $target; - close $c; - return $target; - } else { - return "Permission Denied"; - } -} - -sub set { - my $value = shift; - if (writable()) { - $current = get_current(); - if ($value > $current) { - for (my $i=$current;$i<=$value;$i++) { - open(my $c,'>',"$cur_file"); - print $c $i; - close $c; - } +sub to_percent +{ + my $value = shift; + if ($value eq "Permission Denied") { + return $value; } else { - for (my $i=$current;$i>=$value;$i--) { - open(my $c,'>',"$cur_file"); - print $c $i; - close $c; - } + $value = int($value/get_max()*100); + return $value . '%'; } - return $value; - } else { - return "Permission Denied"; - } } -sub help { - print " +sub get_offset +{ + return int(get_max()/100); +} + +sub get_current +{ + open(my $c,'<',"$cur_file"); + my $current = <$c>; + close $c; + chomp $current; + return $current; +} + +sub get_max +{ + open(my $m,'<',"$max_file"); + my $max = <$m>; + close $m; + chomp $max; + return $max; +} + +sub get_min +{ + return int((get_max()/100)+2); +} + +sub writable +{ + if (! -w $cur_file) { + return 0; + } else { + return 1; + } +} + +sub increment +{ + if (writable()) { + my $current = get_current(); + my $max = get_max(); + my $target = $current+get_offset(); + if ($target > $max) { + $target = $max; + } + open(my $c,'>',"$cur_file"); + print $c $target; + close $c; + return $target; + } else { + return "Permission Denied"; + } +} + +sub decrement +{ + if (writable()) { + my $current = get_current(); + my $min = get_min(); + my $target = $current-get_offset(); + if ($target < $min) { + $target = $min; + } + open(my $c,'>',"$cur_file"); + print $c $target; + close $c; + return $target; + } else { + return "Permission Denied"; + } +} + +sub set +{ + my $value = shift; + if (writable()) { + $current = get_current(); + if ($value > $current) { + for (my $i=$current;$i<=$value;$i++) { + open(my $c,'>',"$cur_file"); + print $c $i; + close $c; + } + } else { + for (my $i=$current;$i>=$value;$i--) { + open(my $c,'>',"$cur_file"); + print $c $i; + close $c; + } + } + return $value; + } else { + return "Permission Denied"; + } +} + +sub help +{ + print " Backlight Control Usage: blc.pl [--silent|--notify] [OPTION] [VALUE] @@ -146,29 +156,30 @@ Print: Any other option will be printed literally"; } -sub advanced { - $current = get_current(); - $max = get_max(); - print ". +sub advanced +{ + $current = get_current(); + $max = get_max(); + print ". Print functions can be strung together but command will exit with the first non-print option. eg. - \$ blc.pl == / ^ - 21/100 - \$ blc.pl == ++ - ('==' ignored) - (Backlight incremented) + \$ blc.pl == / ^ + 21/100 + \$ blc.pl == ++ + ('==' ignored) + (Backlight incremented) Escape options with \\ in quotes to display them literally. eg. - \$ blc.pl == / ^ '\\=' % \'\\%\' - " . $current . "/" . $max . "=" . int($current/$max*100) . "% + \$ blc.pl == / ^ '\\=' % \'\\%\' + " . $current . "/" . $max . "=" . int($current/$max*100) . "% Only one \'\\' is removed per block. eg. - \$ blc.pl '\\% \\' - % \\ + \$ blc.pl '\\% \\' + % \\ "; } @@ -177,107 +188,121 @@ my $current = get_current(); my (@output, $target, $silent, $notify); if (scalar @ARGV) { - for (my $i=0;$i get_max()) { + $target = set(get_max()); + } elsif ($target > 100) { + $target = set($target); + } else { + $target = set( + int((get_max()*$target/100)+1) + ); + } + if ($target eq "Permission Denied") { + @output = $target; + } else { + @output = to_percent($target); + } + last; + } else { + @output = ("No value after $ARGV[$i]"); + last; + } + } elsif ($ARGV[$i] eq '%') { + push @output,int(get_current()/get_max()*100); + } elsif ($ARGV[$i] eq '^') { + push @output,get_max(); + } elsif ($ARGV[$i] eq '==') { + push @output,get_current(); + } elsif ($ARGV[$i] eq '--help') { + help(); + print " (see --HELP).\n\n"; + exit(); + } elsif ($ARGV[$i] eq '--HELP') { + help(); + advanced(); + exit(); + } elsif ($ARGV[$i] eq '--silent') { + $silent = 'TRUE'; + } elsif ($ARGV[$i] =~ /^--notify/) { + $notify = 'TRUE'; + if ($ARGV[$i] =~ /=[0-9]+$/) { + $duration = $ARGV[$i]; + $duration =~ s/.*=([0-9]+)/$1/; + } else { + $duration = 200; + } } else { - $target = set(int((get_max()*$target/100)+1)); + my $add = $ARGV[$i]; + $add =~ s/\\//; + push @output,$add; } - if ($target eq "Permission Denied") { - @output = $target; - } else { - @output = to_percent($target); - } - last; - } else { - @output = ("No value after $ARGV[$i]"); - last; - } - } elsif ($ARGV[$i] eq '%') { - push @output,int(get_current()/get_max()*100); - } elsif ($ARGV[$i] eq '^') { - push @output,get_max(); - } elsif ($ARGV[$i] eq '==') { - push @output,get_current(); - } elsif ($ARGV[$i] eq '--help') { - help(); - print " (see --HELP).\n\n"; - exit(); - } elsif ($ARGV[$i] eq '--HELP') { - help(); - advanced(); - exit(); - } elsif ($ARGV[$i] eq '--silent') { - $silent = 'TRUE'; - } elsif ($ARGV[$i] =~ /^--notify/) { - $notify = 'TRUE'; - if ($ARGV[$i] =~ /=[0-9]+$/) { - $duration = $ARGV[$i]; - $duration =~ s/.*=([0-9]+)/$1/; - } else { - $duration = 200; - } - } else { - my $add = $ARGV[$i]; - $add =~ s/\\//; - push @output,$add; } - } } else { - @output = ('{"Backlight":{"Max":"' . get_max() . '","Current":"' . get_current() . '","Percentage","' . int(get_current()/get_max()*100) . '%"}}'); + @output = ( + '{"Backlight":{"Max":"' + . get_max() + . '","Current":"' + . get_current() + . '","Percentage","' + . int(get_current()/get_max()*100) + . '%"}}' + ); } @@ -286,20 +311,26 @@ print $fh get_current(); close($fh); if ($silent) { - exit(); -} elsif ($notify) { - # Don't output anything if the value didn't change - if ($current == get_current()) { exit(); - } - my $concat; - foreach (@output) { - $concat .= $_; - } - system "notify-send --urgency=normal -i /usr/share/icons/Papirus-Dark-Grey/48x48/status/notification-display-brightness.svg -t $duration \"$concat\""; - exit(); +} elsif ($notify) { + # Don't output anything if the value didn't change + if ($current == get_current()) { + exit(); + } + my $concat; + foreach (@output) { + $concat .= $_; + } + system "notify-send --urgency=normal -i " + . "/usr/share/icons/Papirus-Dark-Grey/48x48/status/" + . "notification-display-brightness.svg -t " + . $duration + . ' "' + . $concat + . '"'; + exit(); } else { - print foreach @output; - print "\n"; - exit(); + print foreach @output; + print "\n"; + exit(); } diff --git a/thinkpad/kbd_backlight.pl b/thinkpad/kbd_backlight.pl index e195341..2107247 100755 --- a/thinkpad/kbd_backlight.pl +++ b/thinkpad/kbd_backlight.pl @@ -8,32 +8,32 @@ my $current = "/sys/class/leds/tpacpi\:\:kbd_backlight/brightness"; my ($max, $now, $new); if (open(my $m, '<', $maxfile)) { - $max = readline($m); - chomp $max; - close($m); + $max = readline($m); + chomp $max; + close($m); } else { - print "Failed to read $maxfile\n"; - exit; + print "Failed to read $maxfile\n"; + exit; } print STDERR "max = $max\n"; if (open(my $c, '<', $current)) { - $now = readline($c); - chomp $now; - close($c); + $now = readline($c); + chomp $now; + close($c); } else { - print "Failed to read $current\n"; - exit; + print "Failed to read $current\n"; + exit; } print STDERR "now = $now\n"; if (open(my $fh, '>', $current)) { - $new = (($now+1) % ($max+1)); - chomp $new; - print $fh $new; - close($fh); + $new = (($now+1) % ($max+1)); + chomp $new; + print $fh $new; + close($fh); } else { - print "Failed to write $current\n"; - exit; + print "Failed to write $current\n"; + exit; } print STDERR "new = $new\n"; diff --git a/thinkpad/user-thinkpad-controls@.service b/thinkpad/user-thinkpad-controls@.service index 7d10487..980dd4a 100644 --- a/thinkpad/user-thinkpad-controls@.service +++ b/thinkpad/user-thinkpad-controls@.service @@ -2,7 +2,9 @@ Description=Give ownership of backlight to %I [Service] -ExecStart=chown %i:%i /sys/class/backlight/intel_backlight/brightness /sys/class/leds/tpacpi::kbd_backlight/brightness +ExecStart=chown %i:%i \ + /sys/class/backlight/intel_backlight/brightness \ + /sys/class/leds/tpacpi::kbd_backlight/brightness [Install] WantedBy=multi-user.target diff --git a/update-firefox.pl b/update-firefox.pl index 149c280..ac83e94 100755 --- a/update-firefox.pl +++ b/update-firefox.pl @@ -11,43 +11,52 @@ my $install = "$ENV{HOME}/.local/bin"; my $working = "/tmp/firefox.new"; # Download link as provided by https://www.mozilla.org/$lang/firefox/developer/ -my $url = 'https://download.mozilla.org/?product=firefox-devedition-latest-ssl&os=linux64&lang='.$lang; +my $url = 'https://download.mozilla.org/?product=firefox-devedition-latest-ssl' + . '&os=linux64&lang='.$lang; # Ensure that we can unzip unless (which("bunzip2")) { - die "Requires bunzip2. Try:\nsudo apt install zutils or your distro's equivalent\n"; + die "Requires bunzip2. Try:\n" + . "sudo apt install zutils or your distro's equivalent\n"; } # Only understood argument is to not bother verifying the package my ($download_key, $verify) = (0,1); if (defined $ARGV[0]) { - if ($ARGV[0] eq '--no-verify') { - $verify = 0; - } else { - die "Didn't understand argument $ARGV[0]\n"; - } + if ($ARGV[0] eq '--no-verify') { + $verify = 0; + } else { + die "Didn't understand argument $ARGV[0]\n"; + } } # If verification is to be done, make sure we have the key unless ($verify) { - print "Checking for Mozilla GPG key in keyring...\n"; - system("gpg --list-keys release\@mozillla.com 2>&1 > /dev/null"); - if ($?) { - my $YN = prompt (-in => *STDIN, "You don't currently have Mozilla's GPG key in your keyring.\nWould you like to install it? If not, installation will not be verified. [y/N]: ", -single); - if ($YN eq 'y' || $YN eq 'Y') { - $download_key = 1; - } else { - $verify = 0; + print "Checking for Mozilla GPG key in keyring...\n"; + system("gpg --list-keys release\@mozillla.com 2>&1 > /dev/null"); + if ($?) { + my $YN = prompt (-in => *STDIN, "You don't currently have " + . "Mozilla's GPG key in your keyring.\n" + . "Would you like to install it? If not, installation " + . "will not be verified. [y/N]: ", + -single + ); + if ($YN eq 'y' || $YN eq 'Y') { + $download_key = 1; + } else { + $verify = 0; + } } - } } # If a previous download still exists remove it if ( -e $working ) { - system("rm -rf $working"); - if ($?) { - die "Working directory $working already exists and failed to remove: $!\n"; - } + system("rm -rf $working"); + if ($?) { + die "Working directory " + . $working + . "already exists and failed to remove: $!\n"; + } } # Get version currently installed @@ -58,19 +67,21 @@ chomp $current; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); -# $url is actually going to redirect to the proper current dowload, so just get the redirect. +# $url is actually going to redirect to the proper current dowload so just get +# the redirect. my $head = $mech->head($url); my ($location, $version); -# This redirect will have the version id, so we can use that to determine if a new version actually exists +# This redirect will have the version id, so we can use that to determine if a +# new version actually exists if ($head->{'_msg'}) { - $version = $location = $head->{'_previous'}->{'_headers'}->{'location'}; - $version =~ s/^.*\-([^\-]*)\.tar\.bz2$/$1/; - if ($version eq $current) { - die "Current ($current) is the same as New ($version)\n"; - } + $version = $location = $head->{'_previous'}->{'_headers'}->{'location'}; + $version =~ s/^.*\-([^\-]*)\.tar\.bz2$/$1/; + if ($version eq $current) { + die "Current ($current) is the same as New ($version)\n"; + } } else { - print "unable to find new download\n"; + print "unable to find new download\n"; } mkdir($working) || die "Couldn't make $working: $!\n"; @@ -78,77 +89,106 @@ mkdir($working) || die "Couldn't make $working: $!\n"; # Download package print "Fetching package $location...\n"; $mech->get($location); -$mech->save_content( $working."/firefox-".$version.".tar.bz2", binmode => ':raw', decoded_by_headers => 1 ); +$mech->save_content( $working."/firefox-".$version.".tar.bz2", + binmode => ':raw', + decoded_by_headers => 1 +); # If verification is required, get signature as well if ($verify) { - $location .= '.asc'; - print "Fetching GPG signature $location...\n"; - $mech->get($location); - $mech->save_content( $working."/firefox-".$version.".tar.bz2.asc", binmode => ':raw', decoded_by_headers => 1 ); + $location .= '.asc'; + print "Fetching GPG signature $location...\n"; + $mech->get($location); + $mech->save_content( $working."/firefox-".$version.".tar.bz2.asc", + binmode => ':raw', + decoded_by_headers => 1 + ); } # If key still needs to be fetched, get it if ($download_key) { - $location =~ s/linux-x86_64.*$/KEY/; - print "Fetching GPG key $location...\n"; - $mech->get($location); - $mech->save_content( $working."/mozilla.pgp", binmode => ':raw', decoded_by_headers => 1 ); - # And install it - print "Installing Mozilla GPG key in keyring...\n"; - system("gpg --import $working/mozilla.pgp 2>&1 > /dev/null"); - if ($?) { - die "Warning: failed to import key. Cannot verify integrity.\nDownloaded to $working. You can check and install it to $install manually: $!\n"; - } - unlink("$working/mozilla.pgp"); + $location =~ s/linux-x86_64.*$/KEY/; + print "Fetching GPG key $location...\n"; + $mech->get($location); + $mech->save_content( $working."/mozilla.pgp", + binmode => ':raw', + decoded_by_headers => 1 + ); + # And install it + print "Installing Mozilla GPG key in keyring...\n"; + system("gpg --import $working/mozilla.pgp 2>&1 > /dev/null"); + if ($?) { + die "Warning: failed to import key. Cannot verify integrity.\n" + . "Downloaded to " + . $working + . ". You can check and install it to " + . $install + . "manually: " + . $! + . "\n"; + } + unlink("$working/mozilla.pgp"); } # Verify the package if ($verify) { - print "Verifying download with Mozilla GPG key...\n"; - system("gpg --verify $working/firefox-$version.tar.bz2.asc"); - if ($?) { - die "Warning: failed to verify download. Signing failed.\nDownloaded to $working. You can check and install it to $install manually: $!\n"; - } + print "Verifying download with Mozilla GPG key...\n"; + system("gpg --verify $working/firefox-$version.tar.bz2.asc"); + if ($?) { + die "Warning: failed to verify download. Signing failed.\n" + . "Downloaded to " + . $working + . ". You can check and install it to " + . $install + . " manually: " + . $! + . "\n"; + } } # Uncompress print "Uncompressing download with bunzip2...\n"; system("bunzip2 $working/firefox-$version.tar.bz2"); if ($?) { - die "Failed to uncompress: $!\n"; + die "Failed to uncompress: $!\n"; } # Extract print "Extracting from TAR archive...\n"; system("tar -xf $working/firefox-$version.tar -C $working"); if ($?) { - die "Failed to extract: $!\n"; + die "Failed to extract: $!\n"; } # Bin the old backup if (-e "$install/.firefox.old") { - print "Removing previous backup folder...\n"; - system("rm -rf $install/.firefox.old"); - if ($?) { - die "Failed to remove: $!\n"; - } + print "Removing previous backup folder...\n"; + system("rm -rf $install/.firefox.old"); + if ($?) { + die "Failed to remove: $!\n"; + } } # Move current to old -print "Backing up currently installed version ($current) to $install/.firefox.old...\n"; +print "Backing up currently installed version (" + . $current + . ") to " + . $install + . "/.firefox.old...\n"; system("mv $install/firefox $install/.firefox.old"); if ($?) { - die "Failed to move: $!\n"; + die "Failed to move: $!\n"; } # Move new to current print "Moving new version to $install for final installation...\n"; system("mv $working/firefox $install/"); if ($?) { - die "Failed to move: $!\n"; + die "Failed to move: $!\n"; } # Hurray! -print "Installation of version $version complete. You should restart firefox whenever it is convenient.\n"; +print "Installation of version " + . $version + . " complete. You should restart firefox whenever it is convenient.\n"; exit(); diff --git a/waybar/waybar-cpu.sh b/waybar/waybar-cpu.sh index 01c19e6..9346057 100755 --- a/waybar/waybar-cpu.sh +++ b/waybar/waybar-cpu.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ "$(pgrep -c htop)" -gt 0 ]; then - pkill htop + pkill htop else - /usr/bin/uxterm -e htop + /usr/bin/uxterm -e htop fi diff --git a/waybar/waybar-disk.sh b/waybar/waybar-disk.sh index 023388e..69495c1 100755 --- a/waybar/waybar-disk.sh +++ b/waybar/waybar-disk.sh @@ -1,3 +1,7 @@ #!/bin/bash -notify-send -t 3000 Disks "$(lsblk -o NAME,SIZE,FSUSE%,MOUNTPOINT | grep -vP '^loop' | sed 's/MOUNTPOINT/MOUNT/' | sed -e 's/│ └─/+---/' | sed -e 's/ └─/+---/' | sed -e 's/├─/+-/' | sed -e 's/└─/+-/' | awk {'printf "%-20s %-7s %- 6s %-7s\n", $1, $2, $3, $4'})" +notify-send -t 3000 Disks \ + "$(lsblk -o NAME,SIZE,FSUSE%,MOUNTPOINT | grep -vP '^loop' | \ + sed 's/MOUNTPOINT/MOUNT/' | sed -e 's/│ └─/+---/' | \ + sed -e 's/ └─/+---/' | sed -e 's/├─/+-/' | sed -e 's/└─/+-/' | \ + awk {'printf "%-20s %-7s %- 6s %-7s\n", $1, $2, $3, $4'})" diff --git a/waybar/waybar-mem.sh b/waybar/waybar-mem.sh index 7f5bbc5..02cf10a 100755 --- a/waybar/waybar-mem.sh +++ b/waybar/waybar-mem.sh @@ -1,3 +1,5 @@ #!/bin/bash -notify-send 'Memory Usage' "`free -h | awk '{printf(\"%6s %6s %6s %6s\n\", $1, $2, $3, $4)}' | sed -r 's/(.*) shared$/ \1/'`" +notify-send 'Memory Usage' "`free -h | \ + awk '{printf(\"%6s %6s %6s %6s\n\", $1, $2, $3, $4)}' | \ + sed -r 's/(.*) shared$/ \1/'`" diff --git a/waybar/waybar-nmtui.sh b/waybar/waybar-nmtui.sh index 1e9dc4e..8d4252a 100755 --- a/waybar/waybar-nmtui.sh +++ b/waybar/waybar-nmtui.sh @@ -1,9 +1,9 @@ #!/bin/bash if [ "$(pgrep -c nmtui | cut -b 1)" -eq "0" ]; then - echo true - /usr/bin/xterm -e '/usr/bin/nmtui' + echo true + /usr/bin/xterm -e '/usr/bin/nmtui' else - echo false - pkill nmtui 2&>1 /dev/null + echo false + pkill nmtui 2&>1 /dev/null fi