From 597a57c242422ea8e760f82f285e404ce2e43a41 Mon Sep 17 00:00:00 2001 From: Christian Krinitsin Date: Tue, 28 May 2024 22:21:23 +0200 Subject: add many different things --- bin/blur-lock | 11 ++ bin/powermenu | 186 +++++++++++++++++++++ bin/volume_brightness | 102 +++++++++++ nvim/.config/nvim/lua/core/keymaps.lua | 2 + nvim/.config/nvim/lua/plugins/lspconfig.lua | 4 + scripts/getty@tty1.service | 60 +++++++ scripts/install-packages.sh | 6 +- scripts/lsp.sh | 2 +- sway/.config/sway/config | 17 +- waybar/.config/waybar/config | 11 +- waybar/.config/waybar/scripts/blur-lock | 11 -- waybar/.config/waybar/scripts/powermenu | 186 --------------------- waybar/.config/waybar/scripts/volume_brightness.sh | 102 ----------- 13 files changed, 385 insertions(+), 315 deletions(-) create mode 100755 bin/blur-lock create mode 100755 bin/powermenu create mode 100755 bin/volume_brightness create mode 100644 scripts/getty@tty1.service delete mode 100755 waybar/.config/waybar/scripts/blur-lock delete mode 100755 waybar/.config/waybar/scripts/powermenu delete mode 100755 waybar/.config/waybar/scripts/volume_brightness.sh diff --git a/bin/blur-lock b/bin/blur-lock new file mode 100755 index 0000000..7b5aa6a --- /dev/null +++ b/bin/blur-lock @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +PICTURE=/tmp/swaylock.png +SCREENSHOT="grim $PICTURE" + +BLUR="5x4" + +$SCREENSHOT +convert $PICTURE -blur $BLUR $PICTURE +swaylock -i $PICTURE +rm $PICTURE diff --git a/bin/powermenu b/bin/powermenu new file mode 100755 index 0000000..ac1d677 --- /dev/null +++ b/bin/powermenu @@ -0,0 +1,186 @@ +#!/usr/bin/env bash +# +# Use rofi/zenity to change system runstate thanks to systemd. +# +# Note: this currently relies on associative array support in the shell. +# +# Inspired from i3pystatus wiki: +# https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu +# +# Copyright 2015 Benjamin Chrétien +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# modified to work with latest rofi update by joekamprad + +####################################################################### +# BEGIN CONFIG # +####################################################################### + +# Use a custom lock script +#LOCKSCRIPT="i3lock-extra -m pixelize" + +# Colors: FG (foreground), BG (background), HL (highlighted) +FG_COLOR="#bbbbbb" +BG_COLOR="#111111" +HLFG_COLOR="#111111" +HLBG_COLOR="#bbbbbb" +BORDER_COLOR="#222222" + +# Options not related to colors (most rofi options do not work anymore) +ROFI_OPTIONS=(-theme ~/.config/rofi/powermenu.rasi) +# Zenity options +ZENITY_TITLE="Power Menu" +ZENITY_TEXT="Action:" +ZENITY_OPTIONS=(--column= --hide-header) + +####################################################################### +# END CONFIG # +####################################################################### + +# Whether to ask for user's confirmation +enable_confirmation=false + +# Preferred launcher if both are available +preferred_launcher="rofi" + +usage="$(basename "$0") [-h] [-c] [-p name] -- display a menu for shutdown, reboot, lock etc. + +where: + -h show this help text + -c ask for user confirmation + -p preferred launcher (rofi or zenity) + +This script depends on: + - systemd, + - sway, + - rofi or zenity." + +# Check whether the user-defined launcher is valid +launcher_list=(rofi zenity) +function check_launcher() { + if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then + echo "Supported launchers: ${launcher_list[*]}" + exit 1 + else + # Get array with unique elements and preferred launcher first + # Note: uniq expects a sorted list, so we cannot use it + i=1 + launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \ + | sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' ')) + fi +} + +# Parse CLI arguments +while getopts "hcp:" option; do + case "${option}" in + h) echo "${usage}" + exit 0 + ;; + c) enable_confirmation=true + ;; + p) preferred_launcher="${OPTARG}" + check_launcher "${preferred_launcher}" + ;; + *) exit 1 + ;; + esac +done + +# Check whether a command exists +function command_exists() { + command -v "$1" &> /dev/null 2>&1 +} + +# systemctl required +if ! command_exists systemctl ; then + exit 1 +fi + +# menu defined as an associative array +typeset -A menu + +# Menu with keys/commands + +menu=( + [ Shutdown]="systemctl poweroff" + [ Reboot]="systemctl reboot" + [ Suspend]="systemctl suspend" + [ Hibernate]="systemctl hibernate" + [ Lock]="~/.config/waybar/scripts/blur-lock" + [ Logout]="swaymsg exit" + [ Cancel]="" +) + +menu_nrows=${#menu[@]} + +# Menu entries that may trigger a confirmation message +menu_confirm="Shutdown Reboot Hibernate Suspend Halt Logout" + +launcher_exe="" +launcher_options="" +rofi_colors="" + +function prepare_launcher() { + if [[ "$1" == "rofi" ]]; then + rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \ + -hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}") + launcher_exe="rofi" + launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \ + "${rofi_colors}" "${ROFI_OPTIONS[@]}") + elif [[ "$1" == "zenity" ]]; then + launcher_exe="zenity" + launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \ + "${ZENITY_OPTIONS[@]}") + fi +} + +for l in "${launcher_list[@]}"; do + if command_exists "${l}" ; then + prepare_launcher "${l}" + break + fi +done + +# No launcher available +if [[ -z "${launcher_exe}" ]]; then + exit 1 +fi + +launcher=(${launcher_exe} "${launcher_options[@]}") +selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")" + +function ask_confirmation() { + if [ "${launcher_exe}" == "rofi" ]; then + confirmed=$(echo -e "Yes\nNo" | rofi -dmenu -i -lines 2 -p "${selection}?" \ + "${rofi_colors}" "${ROFI_OPTIONS[@]}") + [ "${confirmed}" == "Yes" ] && confirmed=0 + elif [ "${launcher_exe}" == "zenity" ]; then + zenity --question --text "Are you sure you want to ${selection,,}?" + confirmed=$? + fi + + if [ "${confirmed}" == 0 ]; then + swaymsg -q "exec --no-startup-id ${menu[${selection}]}" + fi +} + +if [[ $? -eq 0 && ! -z ${selection} ]]; then + if [[ "${enable_confirmation}" = true && \ + ${menu_confirm} =~ (^|[[:space:]])"${selection}"($|[[:space:]]) ]]; then + ask_confirmation + else + swaymsg -q "exec --no-startup-id ${menu[${selection}]}" + fi +fi diff --git a/bin/volume_brightness b/bin/volume_brightness new file mode 100755 index 0000000..f6174ca --- /dev/null +++ b/bin/volume_brightness @@ -0,0 +1,102 @@ +#!/bin/bash +# original source: https://gitlab.com/Nmoleo/i3-volume-brightness-indicator + +# taken from here: https://gitlab.com/Nmoleo/i3-volume-brightness-indicator + +# See README.md for usage instructions +bar_color="#d3c6aa" +volume_step=2 +brightness_step=2.5 +max_volume=100 + +# Uses regex to get volume from pactl +function get_volume { + pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '[0-9]{1,3}(?=%)' | head -1 +} + +# Uses regex to get mute status from pactl +function get_mute { + pactl get-sink-mute @DEFAULT_SINK@ | grep -Po '(?<=Mute: )(yes|no)' +} + +# Uses regex to get brightness from xbacklight +function get_brightness { + brightnessctl | grep "Current brightness" | cut -d '(' -f 2 | cut -d '%' -f 1 +} + +# Returns a mute icon, a volume-low icon, or a volume-high icon, depending on the volume +function get_volume_icon { + volume=$(get_volume) + mute=$(get_mute) + if [ "$mute" == "yes" ] ; then + volume_icon=" " + elif [ "$volume" -eq 0 ]; then + volume_icon=" " + elif [ "$volume" -lt 50 ]; then + volume_icon=" " + else + volume_icon=" " + fi +} + +# Always returns the same icon - I couldn't get the brightness-low icon to work with fontawesome +function get_brightness_icon { + brightness_icon=" " +} + +# Displays a volume notification using dunstify +function show_volume_notif { + volume=$(get_mute) + get_volume_icon + if [ "$mute" == "yes" ]; then + dunstify -t 1000 -r 2593 -u normal "$volume_icon" -h int:value:0 -h string:hlcolor:$bar_color + else + dunstify -t 1000 -r 2593 -u normal "$volume_icon $volume%" -h int:value:$volume -h string:hlcolor:$bar_color + fi +} + +# Displays a brightness notification using dunstify +function show_brightness_notif { + brightness=$(get_brightness) + get_brightness_icon + dunstify -t 1000 -r 2593 -u normal "$brightness_icon $brightness%" -h int:value:$brightness -h string:hlcolor:$bar_color +} + +# Main function - Takes user input, "volume_up", "volume_down", "brightness_up", or "brightness_down" +case $1 in + volume_up) + # Unmutes and increases volume, then displays the notification + pactl set-sink-mute @DEFAULT_SINK@ 0 + volume=$(get_volume) + if [ $(( "$volume" + "$volume_step" )) -gt $max_volume ]; then + pactl set-sink-volume @DEFAULT_SINK@ $max_volume% + else + pactl set-sink-volume @DEFAULT_SINK@ +$volume_step% + fi + show_volume_notif + ;; + + volume_down) + # Raises volume and displays the notification + pactl set-sink-volume @DEFAULT_SINK@ -$volume_step% + show_volume_notif + ;; + + volume_mute) + # Toggles mute and displays the notification + pactl set-sink-mute @DEFAULT_SINK@ toggle + show_volume_notif + ;; + + brightness_up) + # Increases brightness and displays the notification + brightnessctl set +$brightness_step% + show_brightness_notif + ;; + + brightness_down) + # Decreases brightness and displays the notification + brightnessctl set $brightness_step%- + show_brightness_notif + ;; +esac diff --git a/nvim/.config/nvim/lua/core/keymaps.lua b/nvim/.config/nvim/lua/core/keymaps.lua index 3c384d9..f78f23a 100644 --- a/nvim/.config/nvim/lua/core/keymaps.lua +++ b/nvim/.config/nvim/lua/core/keymaps.lua @@ -12,3 +12,5 @@ vim.keymap.set('n', '', ':NvimTreeToggle', {}) vim.keymap.set('n', '', ':bd', {}) vim.keymap.set('n', '', ':bp', {}) vim.keymap.set('n', '', ':bn', {}) + +vim.keymap.set('n', 'ma', ':w:make', {}) diff --git a/nvim/.config/nvim/lua/plugins/lspconfig.lua b/nvim/.config/nvim/lua/plugins/lspconfig.lua index 3c371da..02911e6 100644 --- a/nvim/.config/nvim/lua/plugins/lspconfig.lua +++ b/nvim/.config/nvim/lua/plugins/lspconfig.lua @@ -36,6 +36,10 @@ return { capabilities = require('cmp_nvim_lsp').default_capabilities(), } + require'lspconfig'.texlab.setup{ + capabilities = require('cmp_nvim_lsp').default_capabilities(), + } + vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('UserLspConfig', {}), callback = function(ev) diff --git a/scripts/getty@tty1.service b/scripts/getty@tty1.service new file mode 100644 index 0000000..9e12fb8 --- /dev/null +++ b/scripts/getty@tty1.service @@ -0,0 +1,60 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +[Unit] +Description=Getty on %I +Documentation=man:agetty(8) man:systemd-getty-generator(8) +Documentation=https://0pointer.de/blog/projects/serial-console.html +After=systemd-user-sessions.service plymouth-quit-wait.service getty-pre.target + +# If additional gettys are spawned during boot then we should make +# sure that this is synchronized before getty.target, even though +# getty.target didn't actually pull it in. +Before=getty.target +IgnoreOnIsolate=yes + +# IgnoreOnIsolate causes issues with sulogin, if someone isolates +# rescue.target or starts rescue.service from multi-user.target or +# graphical.target. +Conflicts=rescue.service +Before=rescue.service + +# On systems without virtual consoles, don't start any getty. Note +# that serial gettys are covered by serial-getty@.service, not this +# unit. +ConditionPathExists=/dev/tty0 + +[Service] +# the VT is cleared by TTYVTDisallocate +# The '-o' option value tells agetty to replace 'login' arguments with an +# option to preserve environment (-p), followed by '--' for safety, and then +# the entered username. +ExecStart=-/sbin/agetty -a chris --noclear - $TERM +Type=idle +Restart=always +RestartSec=0 +UtmpIdentifier=%I +StandardInput=tty +StandardOutput=tty +TTYPath=/dev/%I +TTYReset=yes +TTYVHangup=yes +TTYVTDisallocate=yes +IgnoreSIGPIPE=no +SendSIGHUP=yes +ImportCredential=agetty.* +ImportCredential=login.* + +# Unset locale for the console getty since the console has problems +# displaying some internationalized messages. +UnsetEnvironment=LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION + +[Install] +WantedBy=getty.target +DefaultInstance=tty1 diff --git a/scripts/install-packages.sh b/scripts/install-packages.sh index 1fd1cb8..0e0c11e 100755 --- a/scripts/install-packages.sh +++ b/scripts/install-packages.sh @@ -1,10 +1,14 @@ #!/usr/bin/bash # install packages -sudo pacman -S pacman-contrib python-tldextract pass gnupg base-devel libnotify wl-clipboard qt6-wayland xorg-server-xwayland nerd-fonts zoxide waybar bison startup-notification flex wayland-protocols pkg-config cmake gcc alacritty dunst neovim qutebrowser starship xdg-user-dirs zathura zathura-pdf-mupdf meson ninja +sudo pacman -S fzf grim pacman-contrib python-tldextract pass gnupg base-devel libnotify wl-clipboard qt6-wayland xorg-server-xwayland nerd-fonts zoxide waybar bison startup-notification flex wayland-protocols pkg-config cmake gcc alacritty dunst neovim qutebrowser starship xdg-user-dirs zathura zathura-pdf-mupdf meson ninja sudo pacman -S pipewire pipewire-audio pipewire-alsa pipewire-pulse pavucontrol +sudo pacman -S texlive-basic texlive-bibtexextra texlive-latex texlive-mathscience texlive-latexrecommended texlive-latexextra texlive-binextra + +yay -S grimshot + # install rofi and dmenu for wayland git clone https://github.com/lbonn/rofi.git /tmp/rofi cd /tmp/rofi diff --git a/scripts/lsp.sh b/scripts/lsp.sh index d516a87..ad9fc98 100755 --- a/scripts/lsp.sh +++ b/scripts/lsp.sh @@ -1,4 +1,4 @@ #!/usr/bin/bash -sudo pacman -S lua-language-server clang rust-analyzer +sudo pacman -S lua-language-server clang rust-analyzer texlab diff --git a/sway/.config/sway/config b/sway/.config/sway/config index d1ad11d..205dda0 100644 --- a/sway/.config/sway/config +++ b/sway/.config/sway/config @@ -109,18 +109,18 @@ bindsym $mod+t exec rofi -show window -config ~/.config/rofi/rofidmenu.rasi bindsym $mod+Shift+t exec thunderbird bindsym $mod+Shift+w exec qutebrowser bindsym $mod+Return exec alacritty -bindsym $mod+Shift+e exec ~/.config/waybar/scripts/powermenu -bindsym $mod+p exec ~/.config/waybar/scripts/blur-lock +bindsym $mod+Shift+e exec powermenu +bindsym $mod+p exec blur-lock bindsym $mod+Shift+c reload bindsym $mod+Shift+r restart # multimedia -bindsym XF86MonBrightnessUp exec --no-startup-id ~/.config/waybar/scripts/volume_brightness.sh brightness_up -bindsym XF86MonBrightnessDown exec --no-startup-id ~/.config/waybar/scripts/volume_brightness.sh brightness_down -bindsym XF86AudioRaiseVolume exec --no-startup-id ~/.config/waybar/scripts/volume_brightness.sh volume_up -bindsym XF86AudioLowerVolume exec --no-startup-id ~/.config/waybar/scripts/volume_brightness.sh volume_down -bindsym XF86AudioMute exec --no-startup-id ~/.config/waybar/scripts/volume_brightness.sh volume_mute +bindsym XF86MonBrightnessUp exec --no-startup-id volume_brightness brightness_up +bindsym XF86MonBrightnessDown exec --no-startup-id volume_brightness brightness_down +bindsym XF86AudioRaiseVolume exec --no-startup-id volume_brightness volume_up +bindsym XF86AudioLowerVolume exec --no-startup-id volume_brightness volume_down +bindsym XF86AudioMute exec --no-startup-id volume_brightness volume_mute bindsym XF86AudioMicMute exec amixer sset Capture toggle bindsym XF86AudioPlay exec playerctl play-pause bindsym XF86AudioPause exec playerctl play-pause @@ -129,7 +129,7 @@ bindsym XF86AudioPrev exec playerctl previous bindsym $mod+Ctrl+s exec screenshot # custom scripts -bindsym $mod+Shift+o exec zathura-fzf /home/chris/uni/ +bindsym $mod+Shift+o exec zathura-fzf /home/chris/uni/ /home/chris/downloads bindsym $mod+Shift+b exec bluetooth-devices bindsym $mod+w exec qtb-load-session bindsym $mod+Shift+s exec run-spotify-player @@ -143,6 +143,7 @@ exec_always --no-startup-id random-wallpaper input * { xkb_layout "eu" + tap enabled } bar { diff --git a/waybar/.config/waybar/config b/waybar/.config/waybar/config index d12e8d0..0fa2078 100644 --- a/waybar/.config/waybar/config +++ b/waybar/.config/waybar/config @@ -84,7 +84,7 @@ // "hwmon-path": "/sys/class/hwmon/hwmon2/temp1_input", "critical-threshold": 80, "format": "{icon} {temperatureC}°C", - "format-icons": ["", "", ""], + "format-icons": ["", "", ""], "tooltip": false }, "backlight": { @@ -115,19 +115,18 @@ "format-ethernet": " {ipaddr}/{cidr}", "format-linked": " {ifname} (No IP)", "format-disconnected": " ⚠", - "on-click": "nm-connection-editor", + "on-click": "alacritty -e nmtui", "tooltip": false }, "pulseaudio": { // "scroll-step": 1, // %, can be a float "format": "{icon} {volume}%", "format-bluetooth": "{volume}% {icon} ", - "format-bluetooth-muted": " ", - "format-muted": " ", + "format-bluetooth-muted": " ", + "format-muted": " ", "format-icons": { "headphone": "", - "hands-free": "", - "headset": "", + "headset": " ", "phone": "", "portable": "", "car": "", diff --git a/waybar/.config/waybar/scripts/blur-lock b/waybar/.config/waybar/scripts/blur-lock deleted file mode 100755 index 7b5aa6a..0000000 --- a/waybar/.config/waybar/scripts/blur-lock +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -PICTURE=/tmp/swaylock.png -SCREENSHOT="grim $PICTURE" - -BLUR="5x4" - -$SCREENSHOT -convert $PICTURE -blur $BLUR $PICTURE -swaylock -i $PICTURE -rm $PICTURE diff --git a/waybar/.config/waybar/scripts/powermenu b/waybar/.config/waybar/scripts/powermenu deleted file mode 100755 index ac1d677..0000000 --- a/waybar/.config/waybar/scripts/powermenu +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/env bash -# -# Use rofi/zenity to change system runstate thanks to systemd. -# -# Note: this currently relies on associative array support in the shell. -# -# Inspired from i3pystatus wiki: -# https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu -# -# Copyright 2015 Benjamin Chrétien -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# modified to work with latest rofi update by joekamprad - -####################################################################### -# BEGIN CONFIG # -####################################################################### - -# Use a custom lock script -#LOCKSCRIPT="i3lock-extra -m pixelize" - -# Colors: FG (foreground), BG (background), HL (highlighted) -FG_COLOR="#bbbbbb" -BG_COLOR="#111111" -HLFG_COLOR="#111111" -HLBG_COLOR="#bbbbbb" -BORDER_COLOR="#222222" - -# Options not related to colors (most rofi options do not work anymore) -ROFI_OPTIONS=(-theme ~/.config/rofi/powermenu.rasi) -# Zenity options -ZENITY_TITLE="Power Menu" -ZENITY_TEXT="Action:" -ZENITY_OPTIONS=(--column= --hide-header) - -####################################################################### -# END CONFIG # -####################################################################### - -# Whether to ask for user's confirmation -enable_confirmation=false - -# Preferred launcher if both are available -preferred_launcher="rofi" - -usage="$(basename "$0") [-h] [-c] [-p name] -- display a menu for shutdown, reboot, lock etc. - -where: - -h show this help text - -c ask for user confirmation - -p preferred launcher (rofi or zenity) - -This script depends on: - - systemd, - - sway, - - rofi or zenity." - -# Check whether the user-defined launcher is valid -launcher_list=(rofi zenity) -function check_launcher() { - if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then - echo "Supported launchers: ${launcher_list[*]}" - exit 1 - else - # Get array with unique elements and preferred launcher first - # Note: uniq expects a sorted list, so we cannot use it - i=1 - launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \ - | sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' ')) - fi -} - -# Parse CLI arguments -while getopts "hcp:" option; do - case "${option}" in - h) echo "${usage}" - exit 0 - ;; - c) enable_confirmation=true - ;; - p) preferred_launcher="${OPTARG}" - check_launcher "${preferred_launcher}" - ;; - *) exit 1 - ;; - esac -done - -# Check whether a command exists -function command_exists() { - command -v "$1" &> /dev/null 2>&1 -} - -# systemctl required -if ! command_exists systemctl ; then - exit 1 -fi - -# menu defined as an associative array -typeset -A menu - -# Menu with keys/commands - -menu=( - [ Shutdown]="systemctl poweroff" - [ Reboot]="systemctl reboot" - [ Suspend]="systemctl suspend" - [ Hibernate]="systemctl hibernate" - [ Lock]="~/.config/waybar/scripts/blur-lock" - [ Logout]="swaymsg exit" - [ Cancel]="" -) - -menu_nrows=${#menu[@]} - -# Menu entries that may trigger a confirmation message -menu_confirm="Shutdown Reboot Hibernate Suspend Halt Logout" - -launcher_exe="" -launcher_options="" -rofi_colors="" - -function prepare_launcher() { - if [[ "$1" == "rofi" ]]; then - rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \ - -hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}") - launcher_exe="rofi" - launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \ - "${rofi_colors}" "${ROFI_OPTIONS[@]}") - elif [[ "$1" == "zenity" ]]; then - launcher_exe="zenity" - launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \ - "${ZENITY_OPTIONS[@]}") - fi -} - -for l in "${launcher_list[@]}"; do - if command_exists "${l}" ; then - prepare_launcher "${l}" - break - fi -done - -# No launcher available -if [[ -z "${launcher_exe}" ]]; then - exit 1 -fi - -launcher=(${launcher_exe} "${launcher_options[@]}") -selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")" - -function ask_confirmation() { - if [ "${launcher_exe}" == "rofi" ]; then - confirmed=$(echo -e "Yes\nNo" | rofi -dmenu -i -lines 2 -p "${selection}?" \ - "${rofi_colors}" "${ROFI_OPTIONS[@]}") - [ "${confirmed}" == "Yes" ] && confirmed=0 - elif [ "${launcher_exe}" == "zenity" ]; then - zenity --question --text "Are you sure you want to ${selection,,}?" - confirmed=$? - fi - - if [ "${confirmed}" == 0 ]; then - swaymsg -q "exec --no-startup-id ${menu[${selection}]}" - fi -} - -if [[ $? -eq 0 && ! -z ${selection} ]]; then - if [[ "${enable_confirmation}" = true && \ - ${menu_confirm} =~ (^|[[:space:]])"${selection}"($|[[:space:]]) ]]; then - ask_confirmation - else - swaymsg -q "exec --no-startup-id ${menu[${selection}]}" - fi -fi diff --git a/waybar/.config/waybar/scripts/volume_brightness.sh b/waybar/.config/waybar/scripts/volume_brightness.sh deleted file mode 100755 index d98dc69..0000000 --- a/waybar/.config/waybar/scripts/volume_brightness.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash -# original source: https://gitlab.com/Nmoleo/i3-volume-brightness-indicator - -# taken from here: https://gitlab.com/Nmoleo/i3-volume-brightness-indicator - -# See README.md for usage instructions -bar_color="#d3c6aa" -volume_step=2 -brightness_step=2.5 -max_volume=100 - -# Uses regex to get volume from pactl -function get_volume { - pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '[0-9]{1,3}(?=%)' | head -1 -} - -# Uses regex to get mute status from pactl -function get_mute { - pactl get-sink-mute @DEFAULT_SINK@ | grep -Po '(?<=Mute: )(yes|no)' -} - -# Uses regex to get brightness from xbacklight -function get_brightness { - brightnessctl | grep "Current brightness" | cut -d '(' -f 2 | cut -d '%' -f 1 -} - -# Returns a mute icon, a volume-low icon, or a volume-high icon, depending on the volume -function get_volume_icon { - volume=$(get_volume) - mute=$(get_mute) - if [ "$mute" == "yes" ] ; then - volume_icon=" " - elif [ "$volume" -eq 0 ]; then - volume_icon=" " - elif [ "$volume" -lt 50 ]; then - volume_icon=" " - else - volume_icon=" " - fi -} - -# Always returns the same icon - I couldn't get the brightness-low icon to work with fontawesome -function get_brightness_icon { - brightness_icon=" " -} - -# Displays a volume notification using dunstify -function show_volume_notif { - volume=$(get_mute) - get_volume_icon - if [ "$mute" == "yes" ]; then - dunstify -t 1000 -r 2593 -u normal "$volume_icon" -h int:value:0 -h string:hlcolor:$bar_color - else - dunstify -t 1000 -r 2593 -u normal "$volume_icon $volume%" -h int:value:$volume -h string:hlcolor:$bar_color - fi -} - -# Displays a brightness notification using dunstify -function show_brightness_notif { - brightness=$(get_brightness) - get_brightness_icon - dunstify -t 1000 -r 2593 -u normal "$brightness_icon $brightness%" -h int:value:$brightness -h string:hlcolor:$bar_color -} - -# Main function - Takes user input, "volume_up", "volume_down", "brightness_up", or "brightness_down" -case $1 in - volume_up) - # Unmutes and increases volume, then displays the notification - pactl set-sink-mute @DEFAULT_SINK@ 0 - volume=$(get_volume) - if [ $(( "$volume" + "$volume_step" )) -gt $max_volume ]; then - pactl set-sink-volume @DEFAULT_SINK@ $max_volume% - else - pactl set-sink-volume @DEFAULT_SINK@ +$volume_step% - fi - show_volume_notif - ;; - - volume_down) - # Raises volume and displays the notification - pactl set-sink-volume @DEFAULT_SINK@ -$volume_step% - show_volume_notif - ;; - - volume_mute) - # Toggles mute and displays the notification - pactl set-sink-mute @DEFAULT_SINK@ toggle - show_volume_notif - ;; - - brightness_up) - # Increases brightness and displays the notification - brightnessctl set +$brightness_step% - show_brightness_notif - ;; - - brightness_down) - # Decreases brightness and displays the notification - brightnessctl set $brightness_step%- - show_brightness_notif - ;; -esac -- cgit 1.4.1