diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-06-03 19:56:39 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-06-03 19:56:39 +0800 |
| commit | ca968c4e5040f1ff4b5b5e12d9312360d807dcc1 (patch) | |
| tree | 9900920e8f566794560c1519678e344351d2803b /dot-config/bspwm/scripts | |
| parent | 5f3deaff0bf006a1a353e57b82ad48c0e8f143bc (diff) | |
added submodules, change . -> dot (see man stow --dotfiles)
Diffstat (limited to 'dot-config/bspwm/scripts')
21 files changed, 523 insertions, 0 deletions
diff --git a/dot-config/bspwm/scripts/.zshenv b/dot-config/bspwm/scripts/.zshenv new file mode 100644 index 00000000..ab178e65 --- /dev/null +++ b/dot-config/bspwm/scripts/.zshenv @@ -0,0 +1,8 @@ +typeset -U PATH path +export GTK_IM_MODULE='fcitx' +export QT_IM_MODULE='fcitx' +export SDL_IM_MODULE='fcitx' +export XMODIFIERS='@im=fcitx' +export PATH=/home/system/.local/bin:/usr/share/archcraft/scripts:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/system/.config/bspwm/bin:/home/system/scripts +alias vim='lvim' +export EDITOR='lvim' diff --git a/dot-config/bspwm/scripts/bspasfloat b/dot-config/bspwm/scripts/bspasfloat new file mode 100755 index 00000000..b38bae3e --- /dev/null +++ b/dot-config/bspwm/scripts/bspasfloat @@ -0,0 +1,15 @@ +bspc config initial_polarity second_child + +# Run the command specified as the first argument +$1 & disown + +# Wait for the window to be created +sleep 1 + +# Get the ID of the most recently created window +window_id=$(bspc query --windows --node focused | tail -n 1 | awk '{print $1}') + +# Set the state of the window to floating +bspc window $window_id -t floating + +bspc config initial_polarity first_child diff --git a/dot-config/bspwm/scripts/bspasroot b/dot-config/bspwm/scripts/bspasroot new file mode 100755 index 00000000..5d00ca53 --- /dev/null +++ b/dot-config/bspwm/scripts/bspasroot @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# bspwm directory +DIR="$HOME/.config/bspwm" + +# rofi sudo askpass helper +export SUDO_ASKPASS="$DIR"/scripts/rofi_askpass + +# execute the application +sudo -A $1 diff --git a/dot-config/bspwm/scripts/bspbar b/dot-config/bspwm/scripts/bspbar new file mode 100755 index 00000000..62a804ef --- /dev/null +++ b/dot-config/bspwm/scripts/bspbar @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# bspwm directory +DIR="$HOME/.config" + +# fix padding +#bspc config bottom_padding 0 +bspc config top_padding 46 + +# launch polybar +bash "$DIR"/polybar/polybar.sh diff --git a/dot-config/bspwm/scripts/bspbrightness b/dot-config/bspwm/scripts/bspbrightness new file mode 100755 index 00000000..cdf67047 --- /dev/null +++ b/dot-config/bspwm/scripts/bspbrightness @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +## Script to manage brightness on Archcraft. + +# Icons +iDIR='/usr/share/archcraft/icons/dunst' + +# Graphics card +CARD=`ls /sys/class/backlight | head -n 1` + +# Get brightness +get_backlight() { + if [[ "$CARD" == *"intel_"* ]]; then + BNESS=`xbacklight -get` + LIGHT=${BNESS%.*} + else + LIGHT=$(printf "%.0f\n" `light -G`) + fi + echo "${LIGHT}%" +} + +# Get icons +get_icon() { + backlight="$(get_backlight)" + current="${backlight%%%}" + if [[ ("$current" -ge "0") && ("$current" -le "20") ]]; then + icon="$iDIR"/brightness-20.png + elif [[ ("$current" -ge "20") && ("$current" -le "40") ]]; then + icon="$iDIR"/brightness-40.png + elif [[ ("$current" -ge "40") && ("$current" -le "60") ]]; then + icon="$iDIR"/brightness-60.png + elif [[ ("$current" -ge "60") && ("$current" -le "80") ]]; then + icon="$iDIR"/brightness-80.png + elif [[ ("$current" -ge "80") && ("$current" -le "100") ]]; then + icon="$iDIR"/brightness-100.png + fi +} + +# Notify +notify_bl() { + get_icon && dunstify -u low -h string:x-dunst-stack-tag:obbacklight -i "$icon" "Brightness : $(get_backlight)" +} + +# Increase brightness +inc_backlight() { + if [[ "$CARD" == *"intel_"* ]]; then + xbacklight -inc 10 && notify_bl + else + light -A 5 && notify_bl + fi +} + +# Decrease brightness +dec_backlight() { + if [[ "$CARD" == *"intel_"* ]]; then + xbacklight -dec 10 && notify_bl + else + light -U 5 && notify_bl + fi +} + +# Execute accordingly +if [[ "$1" == "--get" ]]; then + get_backlight +elif [[ "$1" == "--inc" ]]; then + inc_backlight +elif [[ "$1" == "--dec" ]]; then + dec_backlight +else + get_backlight +fi diff --git a/dot-config/bspwm/scripts/bspcolorpicker b/dot-config/bspwm/scripts/bspcolorpicker new file mode 100755 index 00000000..ff857986 --- /dev/null +++ b/dot-config/bspwm/scripts/bspcolorpicker @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +## Simple script to pick color quickly. + +color=$(xcolor --format hex --preview-size 255 --scale 10) +image=/tmp/${color}.png + +main() { + if [[ "$color" ]]; then + # copy color code to clipboard + echo $color | tr -d "\n" | xclip -selection clipboard + # generate preview + convert -size 48x48 xc:"$color" ${image} + # notify about it + dunstify -u low -h string:x-dunst-stack-tag:obcolorpicker -i ${image} "$color, copied to clipboard." + fi +} + +# run the script +main diff --git a/dot-config/bspwm/scripts/bspcomp b/dot-config/bspwm/scripts/bspcomp new file mode 100755 index 00000000..5f27c57b --- /dev/null +++ b/dot-config/bspwm/scripts/bspcomp @@ -0,0 +1,13 @@ +#!/usr/bin/bash + +# bspwm directory +DIR="$HOME/.config" + +# Terminate if picom is already running +killall -q picom + +# Wait until the processes have been shut down +while pgrep -u $UID -x picom >/dev/null; do sleep 1; done + +# Launch picom +picom --config "$DIR"/picom.conf -b --show-all-xerrors & # --use-damage --animation-clamping --vsync -blur-background-fixed --blur-background --blur-background-frame diff --git a/dot-config/bspwm/scripts/bspdunst b/dot-config/bspwm/scripts/bspdunst new file mode 100755 index 00000000..d0fabb7c --- /dev/null +++ b/dot-config/bspwm/scripts/bspdunst @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# bspwm directory +DIR="$HOME/.config/dunst" + +# Launch dunst daemon +if [[ `pidof dunst` ]]; then + pkill dunst +fi + +dunst -config "$DIR"/dunstrc & diff --git a/dot-config/bspwm/scripts/bspfloat b/dot-config/bspwm/scripts/bspfloat new file mode 100755 index 00000000..b63192dd --- /dev/null +++ b/dot-config/bspwm/scripts/bspfloat @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +## All windows are floating on desktop 8 +FLOATING_DESKTOP_ID=$(bspc query -D -d '^9') + +bspc subscribe node_add | while read -a msg ; do + desk_id=${msg[2]} + wid=${msg[4]} + [ "$FLOATING_DESKTOP_ID" = "$desk_id" ] && bspc node "$wid" -t floating +done diff --git a/dot-config/bspwm/scripts/bspmusic b/dot-config/bspwm/scripts/bspmusic new file mode 100755 index 00000000..6a95c8f5 --- /dev/null +++ b/dot-config/bspwm/scripts/bspmusic @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +## Run ncmpcpp with alternate config + +# bspwm directory +DIR="$HOME/.config/bspwm" + +CONFIG="$DIR/alacritty/alacritty.yml" + +alacritty --class 'Music,Music' --config-file "$CONFIG" \ + -o window.dimensions.columns=109 window.dimensions.lines=22 \ + -e ~/.ncmpcpp/scripts/ncmpcpp-art + diff --git a/dot-config/bspwm/scripts/bspscreenshot b/dot-config/bspwm/scripts/bspscreenshot new file mode 100755 index 00000000..9403a870 --- /dev/null +++ b/dot-config/bspwm/scripts/bspscreenshot @@ -0,0 +1,93 @@ +#!/usr/bin/env bash + +## Script to take screenshots on Archcraft. + +# file +time=`date +%Y-%m-%d-%H-%M-%S` +geometry=`xrandr | grep 'current' | head -n1 | cut -d',' -f2 | tr -d '[:blank:],current'` +dir="`xdg-user-dir PICTURES`/Screenshots" +file="Screenshot_${time}_${geometry}.png" + +# directory +if [[ ! -d "$dir" ]]; then + mkdir -p "$dir" +fi + +# notify and view screenshot +notify_view () { + notify_cmd_shot='dunstify -u low -h string:x-dunst-stack-tag:obscreenshot -i /usr/share/archcraft/icons/dunst/picture.png' + pngcheck ${dir}/"$file" > /dev/null + if [[ $? -eq 0 ]]; then + #${notify_cmd_shot} "Copied to clipboard." + paplay /usr/share/sounds/freedesktop/stereo/screen-capture.oga &>/dev/null & + viewnior ${dir}/"$file" + else + # the notifcation too annoying + #${notify_cmd_shot} "Screenshot Canceled." + rm "${dir}/$file" + exit 0 + fi + if [[ -e "$dir/$file" ]]; then + ${notify_cmd_shot} "Screenshot Saved." + else + ${notify_cmd_shot} "Screenshot Deleted." + fi +} + +# copy screenshot to clipboard +copy_shot () { + tee "$file" | xclip -selection clipboard -t image/png +} + +# countdown +countdown () { + for sec in `seq $1 -1 1`; do + dunstify -t 1000 -h string:x-dunst-stack-tag:screenshottimer -i /usr/share/archcraft/icons/dunst/timer.png "Taking shot in : $sec" + sleep 1 + done +} + +# take shots +shotnow () { + cd ${dir} && maim -u -f png | copy_shot + notify_view +} + +shot5 () { + countdown '5' + sleep 1 && cd ${dir} && maim -u -f png | copy_shot + notify_view +} + +shot10 () { + countdown '10' + sleep 1 && cd ${dir} && maim -u -f png | copy_shot + notify_view +} + +shotwin () { + cd ${dir} && maim -u -f png -i `xdotool getactivewindow` | copy_shot + notify_view +} + +shotarea () { + cd ${dir} && maim -u -f png -s -b 2 -c 0.35,0.55,0.85,0.25 -l | copy_shot + notify_view +} + +# execute +if [[ "$1" == "--now" ]]; then + shotnow +elif [[ "$1" == "--in5" ]]; then + shot5 +elif [[ "$1" == "--in10" ]]; then + shot10 +elif [[ "$1" == "--win" ]]; then + shotwin +elif [[ "$1" == "--area" ]]; then + shotarea +else + echo -e "Available Options : --now --in5 --in10 --win --area" +fi + +exit 0 diff --git a/dot-config/bspwm/scripts/bspswallow b/dot-config/bspwm/scripts/bspswallow new file mode 100755 index 00000000..93714c74 --- /dev/null +++ b/dot-config/bspwm/scripts/bspswallow @@ -0,0 +1,53 @@ +#!/bin/sh + +# Get class of a wid +get_class() { + id=$1 + if [ -z "$id" ]; then + echo "" + else + xprop -id "$id" | sed -n '/WM_CLASS\|WM_COMMAND/s/.*"\(.*\)".*/\1/p' + fi +} + +swallow() { + addedtodesktop=$2 + lasttermdesktop=$(bspc query -D -n last) + + swallowerid=$1 + swallowingid=$(bspc query -N -n last) + + if [ "$addedtodesktop" = "$lasttermdesktop" ]; then + grep "^$(get_class "$swallowerid")$" ~/.config/bspwm/scripts/swallow || return + grep "^$(get_class "$swallowingid")$" ~/.config/bspwm/scripts/terminals || return + echo "$swallowerid $swallowingid" >> /tmp/swallowids + bspc node "$swallowingid" --flag hidden=on + fi +} + +spit() { + spitterid=$1 + spitterdesktop=$2 + grep "^$spitterid" /tmp/swallowids || return + spittingid=$(grep "^$spitterid" /tmp/swallowids | head -n1 | awk '{print $2}') + + bspc node "$spittingid" --flag hidden=off + + termdesktop=$(bspc query -D -n "$spittingid") + [ "$termdesktop" = "$spitterdesktop" ] || bspc node "$spittingid" -d "$spitterdesktop" + + bspc node "$spittingid" -f + sed -i "/^$spitterid/d" /tmp/swallowids +} + +bspc subscribe node_add node_remove | while read -r event +do + case $(echo "$event" | awk '{ print $1 }') in + node_add) + swallow $(echo "$event" | awk '{print $5 " " $3}') + ;; + node_remove) + spit $(echo "$event" | awk '{print $4 " " $3}') + ;; + esac +done diff --git a/dot-config/bspwm/scripts/bspterm b/dot-config/bspwm/scripts/bspterm new file mode 100755 index 00000000..75e3892c --- /dev/null +++ b/dot-config/bspwm/scripts/bspterm @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +## launch alacritty with bspwm config + +# bspwm directory +DIR="$HOME/.config/bspwm" +CONFIG="$DIR/alacritty/alacritty.yml" + +if [ "$1" == "--float" ]; then + #alacritty --class 'alacritty-float,alacritty-float' --config-file "$CONFIG" + alacritty --class 'alacritty-float,alacritty-float' +elif [ "$1" == "--full" ]; then + #alacritty --class 'Fullscreen,Fullscreen' --config-file "$CONFIG" \ + alacritty --class 'Fullscreen,Fullscreen' \ + -o window.startup_mode=fullscreen \ + window.padding.x=30 window.padding.y=30 \ + window.opacity=0.95 font.size=14 +elif [ "$1" == "--pseudo" ]; then + alacritty --class 'pseudo_tiled' +else +# alacritty --config-file "$CONFIG" + alacritty +fi diff --git a/dot-config/bspwm/scripts/bspvolume b/dot-config/bspwm/scripts/bspvolume new file mode 100755 index 00000000..716c65b2 --- /dev/null +++ b/dot-config/bspwm/scripts/bspvolume @@ -0,0 +1,81 @@ +#!/usr/bin/env bash + +## Script to manage speaker volume on Archcraft. + +# Icons +iDIR='/usr/share/archcraft/icons/dunst' +notify_cmd='dunstify -u low -h string:x-dunst-stack-tag:obvolume' + +# Get Volume +get_volume() { + echo "`pulsemixer --get-volume | cut -d' ' -f1`" +} + +# Get icons +get_icon() { + current="$(get_volume)" + if [[ "$current" -eq "0" ]]; then + icon="$iDIR/volume-mute.png" + elif [[ ("$current" -ge "0") && ("$current" -le "30") ]]; then + icon="$iDIR/volume-low.png" + elif [[ ("$current" -ge "30") && ("$current" -le "60") ]]; then + icon="$iDIR/volume-mid.png" + elif [[ ("$current" -ge "60") && ("$current" -le "100") ]]; then + icon="$iDIR/volume-high.png" + fi +} + +# Notify +notify_user() { + ${notify_cmd} -i "$icon" "Volume : $(get_volume)%" +} + +# Increase Volume +inc_volume() { + [[ `pulsemixer --get-mute` == 1 ]] && pulsemixer --unmute + pulsemixer --max-volume 100 --change-volume +5 & get_icon && notify_user +} + +# Decrease Volume +dec_volume() { + [[ `pulsemixer --get-mute` == 1 ]] && pulsemixer --unmute + pulsemixer --max-volume 100 --change-volume -5 & get_icon && notify_user +} + +# Toggle Mute +toggle_mute() { + if [[ `pulsemixer --get-mute` == 0 ]]; then + pulsemixer --toggle-mute & ${notify_cmd} -i "$iDIR/volume-mute.png" "Mute" + else + pulsemixer --toggle-mute & get_icon && ${notify_cmd} -i "$icon" "Unmute" + fi +} + +# Toggle Mic +toggle_mic() { + ID="`pulsemixer --list-sources | grep 'Default' | cut -d',' -f1 | cut -d' ' -f3`" + if [[ `pulsemixer --id $ID --get-mute` == 0 ]]; then + pulsemixer --id ${ID} --toggle-mute && ${notify_cmd} -i "$iDIR/microphone-mute.png" "Microphone Switched OFF" + else + pulsemixer --id ${ID} --toggle-mute && ${notify_cmd} -i "$iDIR/microphone.png" "Microphone Switched ON" + fi +} + +# Execute accordingly +if [[ -x `which pulsemixer` ]]; then + if [[ "$1" == "--get" ]]; then + get_volume + elif [[ "$1" == "--inc" ]]; then + inc_volume + elif [[ "$1" == "--dec" ]]; then + dec_volume + elif [[ "$1" == "--toggle" ]]; then + toggle_mute + elif [[ "$1" == "--toggle-mic" ]]; then + toggle_mic + else + echo $(get_volume)% + fi +else + ${notify_cmd} "'pulsemixer' is not installed." +fi diff --git a/dot-config/bspwm/scripts/bspwinmask b/dot-config/bspwm/scripts/bspwinmask new file mode 100755 index 00000000..a6211530 --- /dev/null +++ b/dot-config/bspwm/scripts/bspwinmask @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +masked=$(bspc query -N -n .hidden -d focused) + +if [ -z "$masked" ]; then + bspc node focused -g hidden=on +else + bspc node "$masked" -g hidden=off +fi diff --git a/dot-config/bspwm/scripts/drag-to-float b/dot-config/bspwm/scripts/drag-to-float new file mode 100755 index 00000000..be99943a --- /dev/null +++ b/dot-config/bspwm/scripts/drag-to-float @@ -0,0 +1,52 @@ +#!/bin/env bash + +: "${BUTTON:=1}" "${RADIUS:=200}" + +eval "$(xdotool getmouselocation --shell)" +#!/bin/env bash + +: "${BSPWM_DIR:="${XDG_CONFIG_HOME:-$HOME/.config}/bspwm"}" + +#status_file="$BSPWM_DIR/tmp/drag_to_float" +status_file="/tmp/drag-to-float" + +[[ "$1" = stop ]] && { + [[ -e "$status_file" ]] \ + && rm -r -- "$status_file" + exit +} + +[[ -e "$status_file" ]] \ + && exit + +< <(bspc query -T -n pointed.window | jq -r '"\(.id) \(.client.state)"') read -r node node_state + +[[ -z "$node" ]] \ + && exit + +case "$node_state" in + floating) + ;; + tiled|pseudo_tiled) + node_tiled_rect=($(bspc query -T -n "$node" | jq -r '.client.tiledRectangle[]')) + bspc node "$node" -t floating + xdo move -x "${node_tiled_rect[0]}" -y "${node_tiled_rect[1]}" "$node" + xdo resize -w "${node_tiled_rect[2]}" -h "${node_tiled_rect[3]}" "$node" ;; + *) # fullscreen + exit ;; +esac + +eval "$(xdotool getmouselocation --shell)" +x="$X" y="$Y" +touch -- "$status_file" +while [[ -e "$status_file" ]]; do + eval "$(xdotool getmouselocation --shell)" + (( X != x || Y != y )) && { + bspc node "$node" -v "$((X - x))" "$((Y - y))" + x="$X" y="$Y" + } + #sleep .01 +done + +[[ -e "$status_file" ]] \ + && rm -r -- "$status_file" diff --git a/dot-config/bspwm/scripts/keep_state b/dot-config/bspwm/scripts/keep_state new file mode 100755 index 00000000..2fb73782 --- /dev/null +++ b/dot-config/bspwm/scripts/keep_state @@ -0,0 +1,2 @@ +#!/bin/bash +bspc wm -d > ~/.config/bspwm/state diff --git a/dot-config/bspwm/scripts/noswallow b/dot-config/bspwm/scripts/noswallow new file mode 100755 index 00000000..9f23d84e --- /dev/null +++ b/dot-config/bspwm/scripts/noswallow @@ -0,0 +1 @@ +xev diff --git a/dot-config/bspwm/scripts/noswallow_dmenu b/dot-config/bspwm/scripts/noswallow_dmenu new file mode 100755 index 00000000..3afd83a2 --- /dev/null +++ b/dot-config/bspwm/scripts/noswallow_dmenu @@ -0,0 +1,17 @@ +#!/bin/sh +# Allows for dmenu_run to be used without swallowing the terminal + +killall bspswallow +dmenu_run + +# Hang until dmenu is closed +while pidof dmenu; do continue +done + +#If you frequently use dmenu_run without spawing a window commentout this while loop and uncomment the commented out part below +bspc subscribe node_add | while read -r event; do +bspswallow & exit +done + +# sleep 2 +# bspswallow & exit diff --git a/dot-config/bspwm/scripts/noswallow_open b/dot-config/bspwm/scripts/noswallow_open new file mode 100755 index 00000000..81a2a0b0 --- /dev/null +++ b/dot-config/bspwm/scripts/noswallow_open @@ -0,0 +1,7 @@ +#!/bin/sh +# Prefix to a command to make it so that any windows spawned from it don't swallow the terminal +# for launching things from sxhd etc +killall bspswallow +eval $@ >/dev/null +sleep 2 +bspswallow & diff --git a/dot-config/bspwm/scripts/terminals b/dot-config/bspwm/scripts/terminals new file mode 100755 index 00000000..6835a37c --- /dev/null +++ b/dot-config/bspwm/scripts/terminals @@ -0,0 +1,3 @@ +St +Alacritty +Urxvt |
