Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add customizable statusbar #31

Merged
merged 10 commits into from
Sep 15, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added light and dark transparent themes [#18](https://github.com/egel/tmux-gruvbox/issues/18)
- Added editorconfig
- Added code linters for shellcheck & shfmt [#33](https://github.com/egel/tmux-gruvbox/issues/33)
- Added customizable statusbar [#31](https://github.com/egel/tmux-gruvbox/issues/31)

### Changed

Expand Down
103 changes: 85 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,60 +25,126 @@ Theme with 'retro groove' flavor for [Tmux][github-tmux], based on Pavel Pertsev

## Installation

**Available Themes**
### Install via [TPM][github-tpm] (recommended)

- [`dark`](./docs/assets/img/gruvbox-dark-theme.png)
- [`light`](./docs/assets/img/gruvbox-light-theme.png)
- `dark-transparent` (experimental)
- `light-transparent` (experimental)
Add plugin at the top list of TPM plugins in `.tmux.conf` and select desired theme.

```bash
# ~/.tmux.conf
set -g @plugin 'egel/tmux-gruvbox'
# set desired options...
set -g @tmux-gruvbox 'dark' # or 'light'
```

Hit `prefix + I` to fetch the plugin and source it. Your Tmux should be updated with the theme at this point.

### Install manually

The simplest way is just:
1. Clone the project to desired location

> ![TIP] If you do not have github account [download](https://github.com/egel/tmux-gruvbox/archive/refs/heads/main.zip) it and unzip.

```bash
cd ~/projects/
git clone ...
```

> [!TIP]
> Always make a backup of your config files before any action.
1. Add theme at to top of your `~/.tmux.conf` config.

```bash
# ~/.tmux.conf
run ~/projects/tmux-gruvbox/tmux-gruvbox.tmux
# set desired options...
set -g @tmux-gruvbox 'dark' # or light
```

## Configuration options

### Theme

- default value: `dark256`
- available themes:
- [`dark256`](./docs/assets/img/gruvbox-dark-theme.png)
- [`light256`](./docs/assets/img/gruvbox-light-theme.png)

```bash
cat tmux-gruvbox-dark.conf >> ~/.tmux.conf
set -g @tmux-gruvbox 'dark256'
```

### Install through [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm)
### Transparent status-bar

Add plugin to the list of TPM plugins in `.tmux.conf` and select desired theme.
- default value: `'false'`
- tmux >= 3.2 (experimental)

```bash
set -g @plugin 'egel/tmux-gruvbox'
set -g @tmux-gruvbox 'dark' # or 'light', 'dark-transparent', 'light-transparent'
set -g @tmux-gruvbox-statusbar-alpha 'true'
```

Hit `prefix + I` to fetch the plugin and source it. Your Tmux should be updated with the theme at this point.
### Left Status (Section A)

- default value: `'#S'`

```bash
set -g @tmux-gruvbox-left-status-a
```

### Right Status (Section X)

- default value: `'%Y-%m-%d'`

This section is customizable for user, and by default contains current date.

```bash
set -g @tmux-gruvbox-right-status-x
```

### Right Status (Section Y)

- default value: `'%H:%M'`

This section is customizable for user, and by default contains current time.

```bash
# set different time format
set -g @tmux-gruvbox-right-status-y '%H:%M'
```

### Right Status (Section Z)

- default value: `'#h'`

This section is customizable for user, and by default contains hostname.

```bash
# enhance this section with other plugin
set -g @tmux-gruvbox-right-status-z '#h #{tmux_mode_indicator} '
```

## Development

To run project locally:

1. clone the repo to desired place
1. clone the repository to desired place

```bash
cd $HOME/projects/
git clone ...
```

1. create symlink in plugin dir to the cloned repo:
1. create a symlink to the cloned repository (best in the standard [TPM][github-tpm] plugin directory):

```bash
# cd to tmux plugin directory
cd ~/.tmux/plugins/

# create simlink to cloned repo
# create symlink to cloned repo
ln -sf $HOME/projects/tmux-gruvbox/ tmux-gruvbox
```

1. and in `~/.tmux.conf` set

```bash
# add plugin
# ~/.tmux.conf
set -g @plugin 'egel/tmux-gruvbox'
# set desired options...
set -g @tmux-gruvbox 'dark'
Expand All @@ -101,6 +167,7 @@ GPLv3 - Maciej Sypień
[github-hack]: https://github.com/chrissimpkins/Hack
[github-nerd-fonts]: https://github.com/ryanoasis/nerd-fonts
[github-alacritty]: https://github.com/alacritty/alacritty
[github-tpm]: https://github.com/tmux-plugins/tpm
[tmux-color-solarized]: https://github.com/seebi/tmux-colors-solarized
[pexcel-1]: https://www.pexels.com/photo/urban-photo-of-an-alley-2411688/
[pexcel-2]: https://www.pexels.com/photo/lights-hanging-above-the-alley-in-a-city-at-night-27044195/
1 change: 1 addition & 0 deletions gruvbox-tpm.tmux
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash

# shellcheck disable=SC1091
source "./src/gruvbox-main.sh"

# vim: ai et ft=bash
90 changes: 73 additions & 17 deletions src/gruvbox-main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,81 @@
SCRIPT_SRC="$(dirname "${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}")"
readonly SCRIPT_SRC
CURRENT_DIR=$(cd "${SCRIPT_SRC}" >/dev/null 2>&1 && pwd) readonly CURRENT_DIR
readonly THEME_OPTION="@tmux-gruvbox"
readonly DEFAULT_THEME="dark"

get_theme() {
local option="$1"
local default_value="$2"
local option_value
option_value=$(tmux show-option -gqv "$option")
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
readonly CURRENT_DIR

# hold the array of all command to configure tmux theme
declate -a TMUX_CMDS

# load libraries
# shellcheck disable=1091
source "${CURRENT_DIR}/src/helper_methods.sh"
# shellcheck disable=1091
source "${CURRENT_DIR}/src/tmux_utils.sh"

readonly TMUX_GRUVBOX="@tmux-gruvbox"
readonly TMUX_GRUVBOX_STATUSBAR_ALPHA="@tmux-gruvbox-statusbar-alpha"
readonly TMUX_GRUVBOX_LEFT_STATUS_A="@tmux-gruvbox-left-status-a"
readonly TMUX_GRUVBOX_RIGHT_STAUTS_X="@tmux-gruvbox-right-status-x"
readonly TMUX_GRUVBOX_RIGHT_STAUTS_Y="@tmux-gruvbox-right-status-y"
readonly TMUX_GRUVBOX_RIGHT_STAUTS_Z="@tmux-gruvbox-right-status-z"

# define simple theme options (no color interpolation required)
DEFAULT_THEME="dark"
DEFAULT_STATUSBAR_ALPHA=false
# defaults for theme option (with color interpolation)
DEFAULT_LEFT_STATUS_A='#S'
DEFAULT_RIGHT_STATUS_X='%Y-%m-%d'
DEFAULT_RIGHT_STATUS_Y='%H:%M'
DEFAULT_RIGHT_STATUS_Z='#h'

main() {
local theme
theme=$(get_theme "$THEME_OPTION" "$DEFAULT_THEME")
tmux source-file "$CURRENT_DIR/tmux-gruvbox-${theme}.conf"
TMUX_CMDS=() # clear

# load proper palette for the theme asap to avoid additional variable interpolation
local _theme
_theme=$(tmux_get_option "${TMUX_GRUVBOX}" "${DEFAULT_THEME}")
_statusbar_alpha=$(tmux_get_option "${TMUX_GRUVBOX_STATUSBAR_ALPHA}" "${DEFAULT_STATUSBAR_ALPHA}")

case "$_theme" in
light | light256)
# shellcheck disable=1091
source "${CURRENT_DIR}/src/palette_gruvbox_light256.sh"
# shellcheck disable=1091
source "${CURRENT_DIR}/src/theme_gruvbox_light.sh"
;;
dark | dark256 | *)
# shellcheck disable=1091
source "${CURRENT_DIR}/src/palette_gruvbox_dark256.sh"
# shellcheck disable=1091
source "${CURRENT_DIR}/src/theme_gruvbox_dark.sh"
;;
esac

local _status_left _status_right _window_status_current_format _window_status_format
_status_left_a=$(tmux_get_option "$TMUX_GRUVBOX_LEFT_STATUS_A" "$DEFAULT_LEFT_STATUS_A")
_status_right_x=$(tmux_get_option "$TMUX_GRUVBOX_RIGHT_STAUTS_X" "$DEFAULT_RIGHT_STATUS_X")
_status_right_y=$(tmux_get_option "$TMUX_GRUVBOX_RIGHT_STAUTS_Y" "$DEFAULT_RIGHT_STATUS_Y")
_status_right_z=$(tmux_get_option "$TMUX_GRUVBOX_RIGHT_STAUTS_Z" "$DEFAULT_RIGHT_STATUS_Z")

theme_args=(
"$_status_left_a"
"$_status_right_x"
"$_status_right_y"
"$_status_right_z"
"$_statusbar_alpha"
)

case $_theme in
light | light256)
theme_set_light "${theme_args[@]}"
;;
dark | dark256 | *)
theme_set_dark "${theme_args[@]}"
;;
esac

# execute commands with tmux as array of options
tmux "${TMUX_CMDS[@]}"
}

main "$@"
19 changes: 19 additions & 0 deletions src/helper_methods.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# simply print passed array
#
# example
#
# myarray=()
# print_array myarray
#
print_array() {
local -n arr # -n available over bash 4.3
arr=$1

echo ""
echo "begin >>>"
printf "%s\n" "${arr[@]}"
echo "<<< end"
echo ""
}
46 changes: 46 additions & 0 deletions src/palette_gruvbox_dark256.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

##########################
# gruvbox dark pallete
##########################

####
# When using 'colour124' you are using the color default in terminal pallete.
# This could be important for people which terminals support only 256 colors
# and does not support HEX values.
#
# The names of colors used from https://github.com/morhetz/gruvbox

# shellcheck disable=2034 # ignored as this file only contains var definitions
col_bg=colour235
col_bg0_h=colour234
col_bg0=colour235
col_bg1=colour237
col_bg2=colour239
col_bg3=colour241
col_bg4=colour243
col_gray0=colour246
col_gray1=colour245
col_gray2=colour245
col_bg0_s=colour236
col_fg=colour223
col_fg4=colour246
col_fg3=colour248
col_fg2=colour250
col_fg1=colour223
col_fg0=colour229

col_red=colour124
col_red2=colour167
col_green=colour106
col_green2=colour142
col_yellow=colour172
col_yellow2=colour214
col_blue=colour66
col_blue2=colour109
col_purple=colour132
col_purple2=colour175
col_aqua=colour72
col_aqua2=colour108
col_orange=colour166
col_orange2=colour208
46 changes: 46 additions & 0 deletions src/palette_gruvbox_light256.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

##########################
# gruvbox dark pallete
##########################

####
# When using 'colour124' you are using the color default in terminal pallete.
# This could be important for people which terminals support only 256 colors
# and does not support HEX values.
#
# The names of colors used from https://github.com/morhetz/gruvbox

# shellcheck disable=2034 # ignored as this file only contains var definitions
col_bg=colour229
col_bg0_h=colour230
col_bg0=colour229
col_bg1=colour223
col_bg2=colour250
col_bg3=colour248
col_bg4=colour246
col_gray0=colour246
col_gray1=colour245
col_gray2=colour244
col_bg0_s=colour228
col_fg=colour223
col_fg4=colour243
col_fg3=colour241
col_fg2=colour239
col_fg1=colour237
col_fg0=colour235

col_red=colour124
col_red2=colour88
col_green=colour106
col_green2=colour100
col_yellow=colour172
col_yellow2=colour136
col_blue=colour66
col_blue2=colour24
col_purple=colour132
col_purple2=colour96
col_aqua=colour72
col_aqua2=colour66
col_orange=colour166
col_orange2=colour130
Loading