├── README.md ├── example.png ├── tabs.conf └── termtabs /README.md: -------------------------------------------------------------------------------- 1 | # PTTabs 2 | 3 | ![](example.png) 4 | 5 | **Polybar Terminal Tabs:** Some scripts to allow multiple drop-down terminals to be managed with polybar in a tab-like manner. 6 | 7 | ## Dependencies 8 | 9 | **Required:** polybar, tdrop 10 | 11 | **Optional:** bspwm (to make the terminals follow workspace), Google Material Design Icon Font (for default config icons to display) 12 | 13 | ## Installation 14 | 15 | Copy `tabs.conf` to ~/.config 16 | 17 | Copy `termtabs` to your favorite binary folder 18 | 19 | ## Configuration 20 | 21 | Edit `tabs.conf` to set up which terminal runs which app, and set icons or text for those tabs. The comments in this file should make it clear how the configuration works. 22 | 23 | After configuring `tabs.conf`, run the command `termtabs -g` to generate a text file that contains polybar modules to be pasted into your polybar configuration file. After this, you can add the modules to polybar like this: 24 | 25 | ``` 26 | modules-left: tab1 tab2 tab3 tab4 tab5 tab6 27 | ``` 28 | 29 | Finally, make sure to run `termtabs -i` to initialize the file which keeps track of which tabs are opened/closed. This must be run on startup, so make sure to put it into your preferred startup script. 30 | 31 | ## Polybar Configuration Requirements 32 | 33 | The modules that control the tabs require ipc to be enabled in polybar, which can be done with: 34 | 35 | ``` 36 | enable-ipc = true 37 | ``` 38 | 39 | For the default icons to be displayed, one of your fonts in polybar should be the Material Design Icons font. For example: 40 | 41 | ``` 42 | font-0 = Iosevka Term:pixelsize=11;3 43 | font-1 = M+ 1mn:pixelsize=15;3 44 | font-2 = MaterialIcons:size=15:antialias=false;6 45 | ``` 46 | 47 | ## Usage 48 | 49 | The polybar modules can be clicked with the left mouse button, which will call tdrop to open that terminal and position it correctly. To bind these to keyboard shortcuts, take a look at this example sxhkd configuration: 50 | 51 | ``` 52 | super + F1 53 | polybar-msg hook tab1 1 54 | super + F2 55 | polybar-msg hook tab2 1 56 | super + F3 57 | polybar-msg hook tab3 1 58 | super + F4 59 | polybar-msg hook tab4 1 60 | super + F5 61 | polybar-msg hook tab5 1 62 | super + F6 63 | polybar-msg hook tab6 1 64 | ``` 65 | 66 | 67 | -------------------------------------------------------------------------------- /example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nikzt/polybar-terminal-tabs/d64559308661e43631f5051d8ebb53aac8bf350d/example.png -------------------------------------------------------------------------------- /tabs.conf: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Terminal to use in tabs 4 | terminal=st 5 | 6 | # x position relative to top right corner of screen 7 | xoffset=0 8 | 9 | # Additional x offset applied based on tab number to align with buttons 10 | xinterval=0 11 | 12 | # y position relative to top right corner of screen 13 | yoffset=128 14 | 15 | # Terminal width and height 16 | width=591 17 | height=600 18 | 19 | # Color of tab in polybar when tab is open 20 | t_open_col="#435758" 21 | 22 | # Tab closed color 23 | t_closed_col="#1e1e20" 24 | 25 | # Define a tab: tabs[, app]= 26 | # tabs[, icon]= 27 | declare -A tabs 28 | 29 | tabs[1,app]=ranger 30 | tabs[1,icon]= 31 | 32 | tabs[2,app]=calcurse 33 | tabs[2,icon]= 34 | 35 | tabs[3,app]=editnote 36 | tabs[3,icon]= 37 | 38 | tabs[4,app]=termdown 39 | tabs[4,icon]= 40 | 41 | tabs[5,app]=mutt 42 | tabs[5,icon]= 43 | 44 | tabs[6,app]=htop 45 | tabs[6,icon]= 46 | 47 | -------------------------------------------------------------------------------- /termtabs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ~/.config/tabs.conf 4 | 5 | 6 | function show_help { 7 | echo Usage: 8 | echo " -t [TAB NUMBER] -> toggle tab defined by [TAB NUMBER] in config file" 9 | echo " -i -> initialize file that keeps track of tabs" 10 | } 11 | 12 | function toggle_tab { 13 | term_app=${tabs[$tab_num,app]} 14 | icon=${tabs[$tab_num,icon]} 15 | x=$xoffset 16 | 17 | tdrop -a -w $width -h $height -x $x -y $yoffset -n $tab_num -f "-c $terminal -e bash -c 'bspc node -g sticky && $term_app'" $terminal &>/dev/null 18 | 19 | tval=$(update_tab_status) 20 | if [ $tval == 0 ]; then 21 | echo "%{F#eee B$t_closed_col} $tab_num%{F- B-}%{B$t_closed_col} $icon %{B-}" 22 | else 23 | echo "%{F#eee B$t_open_col} $tab_num%{F- B-}%{B$t_open_col} $icon %{B-}" 24 | fi 25 | } 26 | 27 | function update_tab_status { 28 | tabval=$(awk -v lnum="$tab_num" 'NR==lnum{ print $tab_num }' /dev/shm/polybar-tabs) 29 | 30 | if [ $tabval == 0 ]; then 31 | sed -i "${tab_num}s/./1/" /dev/shm/polybar-tabs 32 | tabval=1 33 | else 34 | sed -i "${tab_num}s/./0/" /dev/shm/polybar-tabs 35 | tabval=0 36 | fi 37 | echo $tabval 38 | 39 | } 40 | 41 | function init_tab { 42 | printf "0\n" > /dev/shm/polybar-tabs 43 | for i in `seq 2 $num_tabs`; 44 | do 45 | printf "0\n" >> /dev/shm/polybar-tabs 46 | done 47 | } 48 | 49 | function close_tabs { 50 | num_tabs=$(wc -l < /dev/shm/polybar-tabs) 51 | og_tab_num=$tab_num 52 | for i in `seq 1 $num_tabs`; 53 | do 54 | isopen=$(awk -v lnum="$i" 'NR==lnum{ print $i }' /dev/shm/polybar-tabs) 55 | if [[ $i != $tab_num && $isopen == 1 ]]; then 56 | polybar-msg hook "tab$i" 3 &> /dev/null 57 | 58 | fi 59 | done 60 | } 61 | 62 | function generate_pbar_config { 63 | num_tabs=$(wc -l < /dev/shm/polybar-tabs) 64 | printf "! Polybar Terminal Tabs modules\n! Paste these into your polybar config\n\n" > pttabs_modules 65 | for i in `seq 1 $num_tabs`; 66 | do 67 | icon=${tabs[$i,icon]} 68 | init="%%{F#666 B$t_closed_col} $i%%{F- B-}%%{B$t_closed_col} $icon%%{B-}" 69 | printf "[module/tab$i]\ntype = custom/ipc\n" >> pttabs_modules 70 | printf "hook-0 = termtabs -t $i\n" >> pttabs_modules 71 | printf "hook-1 = echo \"$init\"\n" >> pttabs_modules 72 | printf "hook-2 = termtabs -c 5\n" >> pttabs_modules 73 | printf "click-left = polybar-msg hook tab5 1\n" >> pttabs_modules 74 | printf "initial = 2\n\n" >> pttabs_modules 75 | done 76 | } 77 | 78 | 79 | # A POSIX variable 80 | OPTIND=1 # Reset in case getopts has been used previously in the shell. 81 | 82 | # Initialize our own variables: 83 | output_file="" 84 | verbose=0 85 | 86 | while getopts "h?t:c:i:g" opt; do 87 | case "$opt" in 88 | h|\?) 89 | show_help 90 | exit 0 91 | ;; 92 | t) tab_num=$OPTARG 93 | toggle_tab 94 | close_tabs 95 | ;; 96 | c) tab_num=$OPTARG 97 | toggle_tab 98 | ;; 99 | i) num_tabs=$OPTARG 100 | init_tab 101 | ;; 102 | g) generate_pbar_config 103 | ;; 104 | esac 105 | done 106 | 107 | shift $((OPTIND-1)) 108 | 109 | [ "$1" = "--" ] && shift 110 | 111 | --------------------------------------------------------------------------------