#!/usr/local/bin/perl use strict; use warnings; use Capture::Tiny qw(capture); use WWW::Curl::Easy; use constant { PGREP_PATH => '/bin/pgrep', PKILL_PATH => '/bin/pkill', XRANDR_PATH => '/usr/local/bin/xrandr', MAINSCREEN_PATH => '/usr/home/jozan/.local/bin/mainscreen', DUALSCREEN_PATH => '/usr/home/jozan/.local/bin/dualscreen', TRIPLESCREEN_PATH => '/usr/home/jozan/.local/bin/triplescreen', BSPC_PATH => '/usr/local/bin/bspc', COMPTON_PATH => '/usr/local/bin/compton', FEH_PATH => '/usr/local/bin/feh', XSET_PATH => '/usr/local/bin/xset', SETXKBMAP_PATH => '/usr/local/bin/setxkbmap', DUNST_PATH => '/usr/local/bin/dunst', LOWBAT_PATH => '/usr/local/bin/lowbat', EMACS_PATH => '/usr/local/bin/emacs', ALACRITTY_PATH => '/usr/local/bin/alacritty', DASH_PATH => '/usr/local/bin/dash', SH_PATH => '/bin/sh', ZSH_PATH => '/usr/local/bin/zsh', COWSAY_PATH => '/usr/local/bin/cowsay', ESPEAK_PATH => '/usr/local/bin/espeak', HTOP_PATH => '/usr/local/bin/htop', GOTOP_PATH => '/usr/local/bin/gotop', VIFM_PATH => '/usr/local/bin/vifm', GIT_PATH => '/usr/local/bin/git', QTOX_PATH => '/usr/local/bin/qtox' }; use constant { BSP_BORDER_WIDTH => 1, BSP_WINDOW_GAP => 0, BSP_BORDER_COLOR => '#b92121', BSP_SPLIT_RATIO => '0.50', BSP_BORDERLESS_MONOCLE => 'true', BSP_GAPLESS_MONOCLE => 'true', BSP_SINGLE_MONOCLE => 'true', XSET_R_RATE_DELAY => 200, XSET_R_RATE_RATE => 100, }; use constant WALLPAPER_PATH => '/usr/home/jozan/Pictures/wallpaper.jpg'; use constant COWSAY_WELCOME => 'Welcome back, partner! And remember to try glest!'; use constant NETWORK_TEST_URL => 'https://freebsd.org/'; sub run_if_dead { my @argv = @_; my $bin; my $cat_str; my $i; $bin = $argv[0]; $bin =~ s/.+\///g; my (undef, undef, $retval) = capture { system( PGREP_PATH, $bin ); }; $retval = ($retval >> 8) & 0xff; $cat_str = ''; $i = 0; foreach (@argv) { if ($i == 0 || $_ eq '&') { $cat_str .= $_; } else { $cat_str .= '"' . $_ . '" '; } $i += 1; } if ($retval != 0) { system($cat_str); } return; } sub kill_some { system(PKILL_PATH, 'alacritty'); system(PKILL_PATH, 'compton'); return; } sub enable_screens { my $stdout; my $screens; $screens = 1; ($stdout, undef, undef) = capture { system(XRANDR_PATH); }; if ($stdout =~ m/DP1 connected/ && $stdout =~ m/VGA1 connected/ == 1) { $screens = 3; system(TRIPLESCREEN_PATH); } elsif ($stdout =~ m/DP1 connected/) { $screens = 2; system(DUALSCREEN_PATH); } else { system(MAINSCREEN_PATH); } return $screens; } sub bspc_configs { system(BSPC_PATH, 'config', 'border_width', BSP_BORDER_WIDTH); system(BSPC_PATH, 'config', 'window_gap', BSP_WINDOW_GAP); system(BSPC_PATH, 'config', 'focused_border_color', BSP_BORDER_COLOR); system(BSPC_PATH, 'config', 'split_ratio', BSP_SPLIT_RATIO); system(BSPC_PATH, 'config', 'borderless_monocle', BSP_BORDERLESS_MONOCLE); system(BSPC_PATH, 'config', 'gapless_monocle', BSP_GAPLESS_MONOCLE); system(BSPC_PATH, 'config', 'single_monocle', BSP_SINGLE_MONOCLE); return; } sub bspc_rules { system(BSPC_PATH, 'rule', '-a', 'Emacs', 'state=tiled'); system(BSPC_PATH, 'rule', '-a', 'Firefox', 'desktop=08', 'follow=true'); system(BSPC_PATH, 'rule', '-a', 'Wine', 'desktop=07', 'state=floating'); system(BSPC_PATH, 'rule', '-a', 'Dunst', 'layer=above'); system(BSPC_PATH, 'rule', '-a', 'Zathura', 'state=tiled'); system(BSPC_PATH, 'rule', '-a', 'qTox', 'desktop=12'); system(BSPC_PATH, 'rule', '-a', 'DergodsRealmII', 'state=floating'); return; } sub run_bg_programs { my ($screens) = @_; run_if_dead(COMPTON_PATH, '&'); if ($screens > 1) { system(FEH_PATH, '--bg-fill', WALLPAPER_PATH, '--bg-fill', WALLPAPER_PATH); } else { system(FEH_PATH, '--bg-fill', WALLPAPER_PATH); } system(XSET_PATH, 'r', 'rate', XSET_R_RATE_DELAY, XSET_R_RATE_RATE); system(SETXKBMAP_PATH, '-layout', 'us,fr', '-option', 'grp:alt_shift_toggle'); run_if_dead(DUNST_PATH, '&'); run_if_dead(LOWBAT_PATH, '&'); return; } sub fg_on_three_screens { system(ESPEAK_PATH . ' "' . COWSAY_WELCOME . '" &'); system( ALACRITTY_PATH . ' -e ' . SH_PATH . ' -c \'' . COWSAY_PATH . ' "' . COWSAY_WELCOME . '"; ' . ZSH_PATH . '\' &' ); sleep(1); system(ALACRITTY_PATH . ' -e ' . HTOP_PATH . ' &'); sleep(1); system(ALACRITTY_PATH . ' -e ' . GOTOP_PATH . ' &'); sleep(1); system(BSPC_PATH, 'node', '-f', 'west'); system(ALACRITTY_PATH . ' -e ' . VIFM_PATH . ' &'); sleep(1); system(BSPC_PATH, 'node', '-z', 'right', '180', '0'); system(BSPC_PATH, 'node', '-z', 'top', '0', '70'); system(BSPC_PATH, 'node', '-f', 'east'); system(BSPC_PATH, 'node', '-f', 'north'); system(BSPC_PATH, 'node', '-z', 'bottom', '0', '-280'); system(BSPC_PATH, 'node', '-f', 'north'); system(BSPC_PATH, 'node', '-f', 'west'); return; } sub fg_on_two_screens { system(ESPEAK_PATH, COWSAY_WELCOME, '&'); system( ALACRITTY_PATH . ' -e ' . SH_PATH . ' -c \'' . COWSAY_PATH . ' "' . COWSAY_WELCOME . '"; ' . ZSH_PATH . '\' &' ); sleep(1); system(ALACRITTY_PATH . ' -e ' . HTOP_PATH . ' &'); sleep(1); system(ALACRITTY_PATH, ' -e ', GOTOP_PATH, ' &'); sleep(1); system(BSPC_PATH, 'node', '-f', 'west'); system(ALACRITTY_PATH . ' -e ' . VIFM_PATH . ' &'); sleep(1); system(BSPC_PATH, 'node', '-z', 'right', '180', '0'); system(BSPC_PATH, 'node', '-z', 'top', '0', '70'); system(BSPC_PATH, 'node', '-f', 'east'); system(BSPC_PATH, 'node', '-f', 'north'); system(BSPC_PATH, 'node', '-z', 'bottom', '0', '-280'); system(BSPC_PATH, 'node', '-f', 'north'); system(BSPC_PATH, 'node', '-f', 'west'); return; } sub fg_on_one_screen { system(ESPEAK_PATH, COWSAY_WELCOME, '&'); system( ALACRITTY_PATH . ' -e ' . SH_PATH . ' -c \'' . COWSAY_PATH . ' "' . COWSAY_WELCOME . '"; ' . ZSH_PATH . '\' &' ); sleep(1); system(BSPC_PATH, 'node', '-p', 'west'); system(ALACRITTY_PATH . ' -e ' . HTOP_PATH . ' &'); sleep(1); system(ALACRITTY_PATH . ' -e ' . GOTOP_PATH . ' &'); sleep(1); system(BSPC_PATH, 'node', '-f', 'east'); system(ALACRITTY_PATH . ' -e ' . VIFM_PATH . ' &'); sleep(1); system(BSPC_PATH, 'node', '-f', 'west'); system(BSPC_PATH, 'node', '-f', 'north'); system(BSPC_PATH, 'node', '-z', 'bottom', '0', '-280'); system(BSPC_PATH, 'node', '-z', 'right', '-220', '0'); system(BSPC_PATH, 'node', '-f', 'east'); system(BSPC_PATH, 'node', '-z', 'top', '0', '70'); system(BSPC_PATH, 'node', '-f', 'north'); return; } sub run_fg_programs { my ($screens) = @_; system(BSPC_PATH, 'desktop', '-f', '01'); run_if_dead(EMACS_PATH, '&'); sleep(12); system(BSPC_PATH, 'desktop', '-f', '09'); if ($screens == 3) { fg_on_three_screens(); } elsif ($screens == 2) { fg_on_two_screens(); } else { fg_on_one_screen(); } return; } sub run_network_programs { my $curl; my $response_body; my $retval; $curl = WWW::Curl::Easy->new; $curl->setopt(CURLOPT_URL, NETWORK_TEST_URL); $curl->setopt(CURLOPT_WRITEDATA, \$response_body); $retval = $curl->perform; if ($retval == 0) { system(GIT_PATH, '-C', '/usr/home/jozan/.elfeed', 'pull', 'origin', 'master'); run_if_dead(QTOX_PATH, '&'); } return; } sub main { my $screens; kill_some(); $screens = enable_screens(); bspc_configs(); bspc_rules(); run_bg_programs($screens); run_fg_programs($screens); run_network_programs(); return; } main(); __END__ #!/usr/local/bin/dash run() { if ! pgrep "$1"; then "$@" fi } pkill alacritty pkill compton screens=1 if xrandr | grep VGA1 | grep " connected"; then screens=3 /usr/home/jozan/.local/bin/triplescreen elif xrandr | grep DP1 | grep " connected"; then screens=2 /usr/home/jozan/.local/bin/dualscreen fi sleep 1 if [ $screens -eq 1 ]; then bspc monitor LVDS1 -d 01 02 03 04 05 06 07 08 09 10 11 12 fi bspc config border_width 1 bspc config window_gap 0 bspc config focused_border_color \#b92121 bspc config split_ratio 0.50 bspc config borderless_monocle true bspc config gapless_monocle true bspc config single_monocle true if [ $screens -eq 3 ]; then bspc rule -a Emacs state=tiled bspc rule -a Firefox desktop=08 follow=true bspc rule -a Wine desktop=07 state=floating elif [ $screens -eq 2 ]; then bspc rule -a Emacs state=tiled bspc rule -a Firefox desktop=08 follow=true bspc rule -a Wine desktop=07 state=floating elif [ $screens -eq 1 ]; then bspc rule -a Emacs state=tiled bspc rule -a Firefox desktop=08 follow=true bspc rule -a Wine desktop=04 state=floating fi bspc rule -a Dunst layer=above bspc rule -a Zathura state=tiled bspc rule -a qTox desktop=12 bspc rule -a DergodsRealmII desktop=4 state=floating run compton >/dev/null 2>&1 & if [ $screens -eq 3 ]; then feh --bg-fill /usr/home/jozan/Pictures/wallpaper.jpg --bg-fill /usr/home/jozan/Pictures/wallpaper.jpg >/dev/null 2>&1 elif [ $screens -eq 2 ]; then feh --bg-fill /usr/home/jozan/Pictures/wallpaper.jpg --bg-fill /usr/home/jozan/Pictures/wallpaper.jpg >/dev/null 2>&1 else feh --bg-fill /usr/home/jozan/Pictures/wallpaper.jpg >/dev/null 2>&1 fi xset r rate 200 100 >/dev/null 2>&1 setxkbmap -layout us,fr -option grp:alt_shift_toggle run dunst > /dev/null 2>&1 & run lowbat --say "You're low, partner" >/dev/null 2>&1 & sleep 2 bspc desktop -f 01 run emacs & sleep 12 if [ $screens -eq 3 ]; then bspc desktop -f 09 alacritty -e dash -c 'clear; cowsay "Welcome back, partner! And remember to try glest!"; zsh -i' & sleep 1 alacritty -e htop & sleep 1 alacritty -e gotop & sleep 1 bspc node -f west alacritty -e vifm & sleep 1 bspc node -z right 180 0 bspc node -z top 0 70 bspc node -f east bspc node -f north bspc node -z bottom 0 -280 bspc node -f north bspc node -f west elif [ $screens -eq 2 ]; then bspc desktop -f 09 alacritty -e dash -c 'clear; cowsay "Welcome back, partner! And remember to try glest!"; zsh -i' & sleep 1 alacritty -e htop & sleep 1 alacritty -e gotop & sleep 1 bspc node -f west alacritty -e vifm & sleep 1 bspc node -z right 180 0 bspc node -z top 0 70 bspc node -f east bspc node -f north bspc node -z bottom 0 -280 bspc node -f north bspc node -f west elif [ $screens -eq 1 ]; then bspc desktop -f 09 alacritty -e dash -c 'clear; cowsay "Welcome back, partner!"; zsh -i' & sleep 1 bspc node -p west alacritty -e htop & sleep 1 alacritty -e gotop & sleep 1 bspc node -f east alacritty -e vifm & sleep 1 bspc node -f west bspc node -f north bspc node -z bottom 0 -280 bspc node -z right -220 0 bspc node -f east bspc node -z top 0 70 bspc node -f north fi sleep 1 if curl https://www.freebsd.org/ >/dev/null 2>&1; then git -C ~/.elfeed pull origin master >/dev/null 2>&1 & run qtox & if [ $screens -eq 3 ]; then bspc desktop -f 09 elif [ $screens -eq 2 ]; then bspc desktop -f 09 elif [ $screens -eq 1 ]; then bspc desktop -f 09 fi fi