1
0
mirror of https://gitlab.com/ceda_ei/wish synced 2025-10-23 05:50:05 +02:00

13 Commits

Author SHA1 Message Date
07e406d3f1 Refactor based on linter suggestions 2021-09-24 20:11:30 +05:30
58aefa063b Add support for powerline_left and powerline_right 2021-09-22 13:25:35 +05:30
7cb8857e5e Minor refactor 2021-09-22 13:07:31 +05:30
869a754ede Add theme icy_candy 2021-09-14 16:38:50 +05:30
61ade4610c Use parent directory name if the pwd is .venv 2021-02-14 16:31:18 +05:30
4b9c2b6982 Add theme luminus 2020-05-25 17:17:53 +05:30
cc5eefb197 Update README 2020-01-20 04:24:07 +05:30
de9e43365f Update README 2020-01-18 11:48:00 +05:30
11ad2e081f Update image link in README 2020-01-17 03:38:04 +05:30
1db62a7be8 Update README 2020-01-17 03:30:13 +05:30
e05f37b5b9 Merge branch 'config-file' of ceda/Wish into master
Wish is now configured by a config file (although WISH_PLUGINS and
WISH_RIGHT_PLUGINS are still used as a fallback if no config file is
found. This way old setups won't break). Config file allows for higher
customization and re-use of plugins and is easier to maintain for
users. Add gINIe parser to Wish. Parse a gINIe config file for wish
config. Wrappers around plugins are created to allow re-use with
multiple configs and themes.
2019-12-31 13:41:47 +05:30
c53939cdfe Subtract length of powerline symbols from prompt length max length. 2019-12-31 11:25:55 +05:30
48ff98764d [Feature] Allow WISH_VCS_DEFAULT to be empty 2019-12-29 22:26:08 +05:30
7 changed files with 204 additions and 43 deletions

100
README.md
View File

@@ -1,24 +1,110 @@
# Wish
A customizable bash prompt.
A customizable, extensible, themable bash prompt.
![](https://webionite.com/wish/images/wish.png)
## Features
+ **Extensible**: Parts can be added using simple plugins.
+ **Themable**: Choose from an existing theme or create your own.
+ **Customizable**: The prompt can be customized via a simple config file.
+ **Right Prompt**: Allows for two prompts — one on left, one on right.
+ **Auto newline**: Automatically adds a newline if the last output doesn't end with one.
+ **Powerline support**: Supports powerline symbols in both prompts.
# Installation
## One step Installation
`curl https://gitlab.com/ceda_ei/wish/raw/master/install.sh | bash`
```sh
curl https://gitlab.com/ceda_ei/wish/raw/master/install.sh | bash
```
## Manual Installation
+ `cd ~/.config/`
+ `git clone https://gitlab.com/ceda_ei/wish.git`
+ Add the following lines to ~/.bashrc
+ `cp wish/config.default.gie wish/config.gie`
# Customization
Customization of wish is done using a gINIe file (format specific to wish)
which is an extended INI config file. The default location for config file is
`~/.config/wish/config.gie`. The default config file is automatically copied
over. The location can be customized using `WISH_CONFIG_FILE` variable.
Multiple config files can be supplied as an array to `WISH_CONFIG_FILE`.
Comments start with a `#` or `;` and always exist on a line of their own.
Key value pairs are in the form of `key = value`. Keys cannot have whitespaces
or `=` in them. Values can have any character as part of them. Surrounding
spaces in values are stripped away. To keep surrounding spaces as a part of
the value. Although, keys are case-sensitive in gINIe, wish treats them case-
insensitively.
Block names are enclosed in `[]` (e.g. `[core]`). Block names are case
sensitive. All key value pairs after a block starts and before the next block
begins are considered a part of that block. All key value pairs must be in a
block.
Available Blocks:
+ `core`: Core block configures Wish itself. Available keys are:
- `auto_newline`: Automatically add a newline if last line of output
doesn't end in newline. (0 to disable, 1 to enable)
- `theme`: Wish theme.
- `powerline`: Enable / Disable powerline. (0 to disable, 1 to enable)
+ `plugin`: Adds a plugin to the section the block is added to. All config for
that plugin goes there. Check wiki for details on available keys for
plugins. The key "name" defines the plugin to use. Plugin blocks
outside a section are ignored.
Section names are enclosed in `||` (e.g. `|left|`). All blocks after a section
starts and before the next section begins are considered a part of that
section. Blocks don't necessarily need to be in a section.
Available sections are `left`, `right` for left prompt and right prompt
respectively.
Sample config file
```bash
WISH_PLUGINS=(exit_code_smiley bg_jobs date path newline vcs)
WISH_THEME=plain
source ~/.config/wish/wish.sh
```
[core]
auto_newline = 1
powerline = 1
theme = rgb_gradient
|left|
[plugin]
name = path_powerline
max_perc = 50
[plugin]
name = python_venv
[plugin]
name = newline
[plugin]
name = custom_text
text = ' λ '
[plugin]
name = space
|right|
[plugin]
name = date
format = %a %b %H:%M
[plugin]
name = hostname
```
Which results in the following prompt
![](https://webionite.com/wish/images/prompt.png)
# Wiki

View File

@@ -24,7 +24,7 @@ function wish_path_lensum() {
function wish_path_powerline_shrink() {
local IFS='/'
local path=( $1 )
local max=$2
local max=$(( $2 - 3 * ${#path[@]} ))
for ((i=0; i <$((${#path[@]} - 1)); i++)); do
path[$i]=${path[$i]:0:1}
if [[ $(wish_path_lensum ${path[@]}) -lt $max ]]; then

View File

@@ -13,7 +13,7 @@ function wish_python_venv_set_colors() {
function wish_python_venv_main() {
if [[ -v VIRTUAL_ENV ]]; then
local venv=$(echo $VIRTUAL_ENV | sed 's|.*/||')
local venv=$(echo $VIRTUAL_ENV | sed ';s|/.venv$||;s|.*/||')
wish_append $WISH_PYTHON_VENV_BG $WISH_PYTHON_VENV_FG " $venv "
else
wish_append $WISH_PYTHON_VENV_BG $WISH_PYTHON_VENV_FG ""

View File

@@ -10,7 +10,7 @@ function wish_vcs_set_colors() {
WISH_VCS_FG=${WISH_VCS_FG:-$WISH_DEFAULT_FG}
WISH_VCS_BG=${WISH_VCS_BG:-$WISH_DEFAULT_BG}
WISH_VCS_GIT_SYMBOL=${WISH_VCS_GIT:-}
WISH_VCS_DEFAULT=${WISH_VCS_DEFAULT:-$}
[[ -v WISH_VCS_DEFAULT ]] || WISH_VCS_DEFAULT="$"
WISH_VCS_GIT_UNTRACKED_SYMBOL=${WISH_VCS_GIT_UNTRACKED_SYMBOL:-}
}
@@ -32,7 +32,7 @@ function wish_vcs_main() {
fi
wish_append $WISH_VCS_BG $WISH_VCS_FG "$git"
else
wish_append $WISH_VCS_BG $WISH_VCS_FG " $WISH_VCS_DEFAULT "
wish_append $WISH_VCS_BG $WISH_VCS_FG "$WISH_VCS_DEFAULT"
fi
}

32
themes/icy_candy.sh Normal file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
function wish_icy_candy_theme {
local i
local l_gradient=(f5a9b8 f6b7c3 f8c5cf fad4db fbe2e7 fdf0f3 ffffff)
local r_gradient=(5bcefa 76d6fa 91defb ade6fc c8eefd e3f6fe ffffff)
local fg_gradient=(000000 000000 000000 000000 000000 000000 000000)
local j=0
for i in "${WISH_PLUGINS[@]}"; do
[[ $i =~ newline$ ]] && j=0 && continue
eval "WISH_${i^^}_FG=${fg_gradient[$j]}"
eval "WISH_${i^^}_BG=${l_gradient[$j]}"
((j++))
if [[ $j -eq ${#l_gradient[@]} ]]; then
j=0
fi
done
j=0
for ((idx=$((${#WISH_RIGHT_PLUGINS[@]} - 1)); idx >= 0; idx--)); do
i=${WISH_RIGHT_PLUGINS[$idx]}
[[ $i =~ newline$ ]] && j=0 && continue
eval "WISH_${i^^}_BG=${r_gradient[$j]}"
eval "WISH_${i^^}_FG=${fg_gradient[$j]}"
((j++))
if [[ $j -eq ${#r_gradient[@]} ]]; then
j=0
fi
done
}
wish_icy_candy_theme

31
themes/luminus.sh Normal file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/env bash
function wish_luminous_theme {
local i
local gradient=(ef7126 f7894c fea16f ffb892 ffd0b5 ffe7da ffffff)
local fg_gradient=(000000 000000 000000 000000 000000 000000 000000)
local j=0
for i in "${WISH_PLUGINS[@]}"; do
[[ $i =~ newline$ ]] && j=0 && continue
eval "WISH_${i^^}_FG=${fg_gradient[$j]}"
eval "WISH_${i^^}_BG=${gradient[$j]}"
((j++))
if [[ $j -eq ${#gradient[@]} ]]; then
j=0
fi
done
j=0
for ((idx=$((${#WISH_RIGHT_PLUGINS[@]} - 1)); idx >= 0; idx--)); do
i=${WISH_RIGHT_PLUGINS[$idx]}
[[ $i =~ newline$ ]] && j=0 && continue
eval "WISH_${i^^}_BG=${gradient[$j]}"
eval "WISH_${i^^}_FG=${fg_gradient[$j]}"
((j++))
if [[ $j -eq ${#gradient[@]} ]]; then
j=0
fi
done
}
wish_luminous_theme

76
wish.sh
View File

@@ -1,10 +1,11 @@
#!/usr/bin/env bash
# shellcheck disable=SC1090
# INTERNAL USE ONLY! Do not use this in plugins.
function wish_print_right_prompt() {
local idx=0
for i in ${WISH_RPL[@]}; do
echo "\e[$(($COLUMNS - $i + 1))G${WISH_RIGHT_PS1[$idx]}"
for i in "${WISH_RPL[@]}"; do
echo "\e[$((COLUMNS - i + 1))G${WISH_RIGHT_PS1[idx]}"
((idx++))
done
}
@@ -22,10 +23,14 @@ function wish_init() {
# Source config files
for path in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
if [[ -f "$path/wish/wish.py" ]]; then
source <($path/wish/wish.py ${WISH_CONFIG_FILE[@]})
source <("$path/wish/wish.py" "${WISH_CONFIG_FILE[@]}")
break
fi
done
# Set defaults for core if not found
: "${WISH_POWERLINE_LEFT:=}"
: "${WISH_POWERLINE_RIGHT=}"
# Source all plugins
# If WISH_CONFIG_FILE is not set, then assume that the user hasn't updated
# to a config file yet. Set WISH_PLUGINS_SOURCE=WISH_PLUGINS.
@@ -34,20 +39,20 @@ function wish_init() {
fi
local plugin
local path
for plugin in ${WISH_PLUGINS_SOURCE[@]}; do
for path in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
for plugin in "${WISH_PLUGINS_SOURCE[@]}"; do
if ! for path in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
source "$path/wish/plugins/$plugin.sh" &> /dev/null && break
done
[[ $? -ne 0 ]] && echo "Plugin $plugin not found." >&2
done; then
echo "Plugin $plugin not found." >&2
fi
done
# Source theme
WISH_THEME=${WISH_THEME:-plain}
while :; do
for theme in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
if for theme in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
source "$theme/wish/themes/$WISH_THEME.sh" &> /dev/null && break
done
if [[ $? -eq 0 ]]; then
done; then
break
else
echo "Theme $WISH_THEME not found. Using theme plain." >&2
@@ -60,8 +65,8 @@ function wish_init() {
done
# Call plugins to set colors
for plugin in ${WISH_PLUGINS[@]} ${WISH_RIGHT_PLUGINS[@]}; do
eval wish_$(echo $plugin)_set_colors $prev
for plugin in "${WISH_PLUGINS[@]}" "${WISH_RIGHT_PLUGINS[@]}"; do
"wish_${plugin}_set_colors" "$prev"
done
}
@@ -97,7 +102,7 @@ function wish_append_left() {
local prompt_text="${text@P}"
if [[ $text == "\n" ]]; then
((WISH_LPLINE++))
WISH_LPL=(${WISH_LPL[@]} 0)
WISH_LPL=("${WISH_LPL[@]}" 0)
WISH_LEFT_PS1="$WISH_LEFT_PS1$colors$text"
else
if [[ $((${WISH_LPL[$WISH_LPLINE]} + ${#prompt_text})) -lt $COLUMNS ]]; then
@@ -116,7 +121,7 @@ function wish_append_right() {
if [[ $text == "\n" ]]; then
((WISH_RPLINE++))
WISH_RIGHT_PS1=("${WISH_RIGHT_PS1[@]}" "")
WISH_RPL=(${WISH_RPL[@]} 0)
WISH_RPL=("${WISH_RPL[@]}" 0)
elif [[ $((${WISH_LPL[$WISH_RPLINE]} + ${WISH_RPL[$WISH_RPLINE]} + ${#prompt_text})) -lt $COLUMNS ]]; then
WISH_RIGHT_PS1[$WISH_RPLINE]="${WISH_RIGHT_PS1[$WISH_RPLINE]}$colors$text"
WISH_RPL[$WISH_RPLINE]=$((${WISH_RPL[$WISH_RPLINE]} + ${#prompt_text}))
@@ -136,8 +141,10 @@ function wish_append() {
local bg_code=$1
local fg_code=$2
local text=$3
local fg=$(color_to_escape_code 3 $fg_code)
local bg=$(color_to_escape_code 4 $bg_code)
local fg
local bg
fg=$(color_to_escape_code 3 "$fg_code")
bg=$(color_to_escape_code 4 "$bg_code")
if [[ $fg_code == -1 ]]; then
case $WISH_STATE in
@@ -167,9 +174,9 @@ function wish_append() {
# line.
wish_remaining_chars() {
if [[ $WISH_STATE -eq 0 ]]; then
echo "$(( $COLUMNS - ${WISH_LPL[$WISH_LPLINE]} ))"
echo "$(( COLUMNS - ${WISH_LPL[$WISH_LPLINE]} ))"
else
echo "$(( $COLUMNS - ${WISH_LPL[$WISH_RPLINE]} - ${WISH_RPL[$WISH_RPLINE]} ))"
echo "$(( COLUMNS - ${WISH_LPL[$WISH_RPLINE]} - ${WISH_RPL[$WISH_RPLINE]} ))"
fi
}
@@ -186,8 +193,11 @@ function wish_main() {
WISH_LPLINE=0
local i
# Set newline
if [[ $WISH_AUTONEWLINE != 0 ]]; then
echo -ne "\033[6n" ; read -s -d ';'; read -s -d R WISH_CURSOR_POSITION
if [[ $WISH_AUTO_NEWLINE != 0 ]]; then
echo -ne "\033[6n"
read -rs -d ';'
# shellcheck disable=SC2034
read -rs -d R WISH_CURSOR_POSITION
if [[ $WISH_CURSOR_POSITION != "1" ]]; then
PS1="\n"
fi
@@ -195,21 +205,21 @@ function wish_main() {
# Generate left prompt.
WISH_STATE=0 # 0 = left prompt, 1 = right prompt
for i in $(seq 0 $((${#WISH_PLUGINS[@]} - 1))); do
wish_${WISH_PLUGINS[i]}_main $prev
"wish_${WISH_PLUGINS[i]}_main" "$prev"
if [[ -v WISH_POWERLINE ]] && [[ $WISH_POWERLINE != 0 ]]; then
if wish_${WISH_PLUGINS[$i]}_end $prev; then
if "wish_${WISH_PLUGINS[$i]}_end" $prev; then
if [[ $i -lt $((${#WISH_PLUGINS[@]} - 1)) ]]; then
if wish_${WISH_PLUGINS[$(($i + 1))]}_start $prev; then
if "wish_${WISH_PLUGINS[$((i + 1))]}_start" "$prev"; then
local plugin=${WISH_PLUGINS[$i]}
local next_plugin=${WISH_PLUGINS[$(($i+1))]}
local next_plugin=${WISH_PLUGINS[$((i + 1))]}
local fg_name="WISH_${plugin^^}_BG"
local bg_name="WISH_${next_plugin^^}_BG"
wish_append ${!bg_name} ${!fg_name}
wish_append "${!bg_name}" "${!fg_name}" "${WISH_POWERLINE_LEFT}"
fi
else
local plugin=${WISH_PLUGINS[$i]}
local fg_name="WISH_${plugin^^}_BG"
wish_append -1 ${!fg_name}
wish_append -1 "${!fg_name}" "${WISH_POWERLINE_LEFT}"
fi
fi
fi
@@ -218,26 +228,28 @@ function wish_main() {
WISH_STATE=1
for i in $(seq 0 $((${#WISH_RIGHT_PLUGINS[@]} - 1))); do
if [[ -v WISH_POWERLINE ]] && [[ $WISH_POWERLINE != 0 ]]; then
if wish_${WISH_RIGHT_PLUGINS[$i]}_end $prev; then
if "wish_${WISH_RIGHT_PLUGINS[$i]}_end" "$prev"; then
if [[ $i == 0 ]]; then
local plugin=${WISH_RIGHT_PLUGINS[$i]}
local fg_name="WISH_${plugin^^}_BG"
wish_append -1 ${!fg_name}
elif wish_${WISH_RIGHT_PLUGINS[$(($i - 1))]}_start $prev; then
wish_append -1 "${!fg_name}" "${WISH_POWERLINE_RIGHT}"
elif "wish_${WISH_RIGHT_PLUGINS[$((i - 1))]}_start" $prev; then
local plugin=${WISH_RIGHT_PLUGINS[$i]}
local prev_plugin=${WISH_RIGHT_PLUGINS[$(($i-1))]}
local prev_plugin=${WISH_RIGHT_PLUGINS[$((i - 1))]}
local fg_name="WISH_${plugin^^}_BG"
local bg_name="WISH_${prev_plugin^^}_BG"
wish_append ${!bg_name} ${!fg_name}
wish_append "${!bg_name}" "${!fg_name}" "${WISH_POWERLINE_RIGHT}"
fi
fi
fi
wish_${WISH_RIGHT_PLUGINS[$i]}_main $prev
"wish_${WISH_RIGHT_PLUGINS[$i]}_main" "$prev"
done
# Save cursor position, print right prompt, restore cursor position,
# print left prompt, reset terminal
# shellcheck disable=SC2025
PS1=$PS1"\[\e7"
PS1="$PS1$(wish_print_right_prompt)"
# shellcheck disable=SC2025
PS1="$PS1\e8\]$WISH_LEFT_PS1\[\033[0;5;0m\]"
}