Skip to content

Commit

Permalink
Merge pull request #600 from elg/master
Browse files Browse the repository at this point in the history
feat(themes/powerline-icon): support `OMB_THEME_POWERLINE_ICON_CLOCK` for the date string in segment `user_info`
  • Loading branch information
akinomyoga authored Sep 10, 2024
2 parents 08e297c + 275b606 commit 8cc21b7
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 236 deletions.
34 changes: 34 additions & 0 deletions themes/powerline-icon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Powerline Icon Theme

A theme derived from Powerline with emoji icons.

This is based on the Powerline theme. Please see also [the documentation of the
powerline theme](../powerline/README.md).

![Screenshot](./powerline-icon-dark.png?raw=true)

## Segments

The `powerline-icon` theme modifies the segments `user_info` and `cwd` of the
original Powerline theme so that they include icons. This theme also inserts a
date string in `user_info`.

## Configuration

Icons can be configured by setting values to the following shell variables.

```
OMB_THEME_POWERLINE_ICON_USER
OMB_THEME_POWERLINE_ICON_HOME
OMB_THEME_POWERLINE_ICON_EXIT_FAILURE
OMB_THEME_POWERLINE_ICON_EXIT_SUCCESS
```

The time format shown in the `user_info` segment can be configured by the
following shell variable:

```
OMB_THEME_POWERLINE_ICON_CLOCK
```

The default value is `%X %D`.
41 changes: 22 additions & 19 deletions themes/powerline-icon/powerline-icon.base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,41 @@ source "$OSH/themes/powerline/powerline.base.sh"

function __powerline_user_info_prompt {
local user_info=""
local color=${USER_INFO_THEME_PROMPT_COLOR}
local secondary_color="${USER_INFO_THEME_PROMPT_SECONDARY_COLOR}"
local color=$USER_INFO_THEME_PROMPT_COLOR
local secondary_color=$USER_INFO_THEME_PROMPT_SECONDARY_COLOR

if [[ "${THEME_CHECK_SUDO}" = true ]]; then
if [[ $THEME_CHECK_SUDO == true ]]; then
# check whether sudo is active for no-password executions
if sudo -n cat <<< c3bcc5c 2>&1 | grep -q c3bcc5c; then
color=${USER_INFO_THEME_PROMPT_COLOR_SUDO}
fi
fi
case "${POWERLINE_PROMPT_USER_INFO_MODE}" in
"sudo")
if [[ "${color}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then
user_info="!"
fi
;;
*)
if [[ -n "${SSH_CLIENT}" ]]; then
user_info="${USER_INFO_SSH_CHAR}${USER}@${HOSTNAME}"
else
user_info="${USER}"
fi
;;
case $POWERLINE_PROMPT_USER_INFO_MODE in
"sudo")
if [[ $color == "$USER_INFO_THEME_PROMPT_COLOR_SUDO" ]]; then
user_info="!"
fi
;;
*)
if [[ $SSH_CLIENT ]]; then
user_info=$USER_INFO_SSH_CHAR$USER@$HOSTNAME
else
user_info=$USER
fi
;;
esac
[[ -n "${user_info}" ]] && _omb_util_print "$OMB_THEME_POWERLINE_ICON_USER ${user_info} `date +%X\ %D`|${color}|${secondary_color}"
if [[ $user_info ]]; then
local clock=$(date +"${OMB_THEME_POWERLINE_ICON_CLOCK-%X %D}")
_omb_util_print "$OMB_THEME_POWERLINE_ICON_USER $user_info${clock:+ $clock}|$color|$secondary_color"
fi
}

function __powerline_cwd_prompt {
_omb_util_print "$(pwd | sed "s|^${HOME}|$OMB_THEME_POWERLINE_ICON_HOME|")|${CWD_THEME_PROMPT_COLOR}"
_omb_util_print "$(pwd | sed "s|^$HOME|$OMB_THEME_POWERLINE_ICON_HOME|")|$CWD_THEME_PROMPT_COLOR"
}

function __powerline_last_status_prompt {
if [[ "$1" -ne 0 ]]; then
if (($1 != 0)); then
_omb_util_print "$OMB_THEME_POWERLINE_ICON_EXIT_FAILURE${1}|${LAST_STATUS_THEME_PROMPT_COLOR}"
else
_omb_util_print "$OMB_THEME_POWERLINE_ICON_EXIT_SUCCESS|${LAST_STATUS_THEME_PROMPT_COLOR_SUCCESS}"
Expand Down
58 changes: 3 additions & 55 deletions themes/powerline-light/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,7 @@ A Powerline-derived theme for light backgrounds aiming to balance bling and util

The colours were set using some experimentation and consulting an xterm 256 colour chart like [this](https://github.com/gawin/bash-colors-256)

**IMPORTANT:** This theme requires that [a font with the Powerline symbols](https://github.com/powerline/fonts) needs to be used in your terminal emulator, otherwise the prompt won't be displayed correctly, i.e. some of the additional icons and characters will be missing. Please follow your operating system's instructions to install one of the fonts from the above link and select it in your terminal emulator.
This is based on the Powerline theme. Please see also [the documentation of the
powerline theme](../powerline/README.md).

**NOTICE:** The default behavior of this theme assumes that you have sudo privileges on your workstation. If that is not the case (e.g. if you are running on a corporate network where `sudo` usage is tracked), you can set the flag 'export THEME_CHECK_SUDO=false' in your `~/.bashrc` or `~/.bash_profile` to disable the Powerline theme's `sudo` check. This will apply to all `powerline*` themes.

## Provided Information

* Current path
* Current username and hostname
* Current time
* An indicator when connected by SSH
* An indicator when `sudo` has the credentials cached (see the `sudo` manpage for more info about this)
* An indicator when the current shell is inside the Vim editor
* Battery charging status (depends on the [../../plugins/battery/battery.plugin.sh](battery plugin))
* SCM Repository status (e.g. Git, SVN)
* The current Python environment (Virtualenv, venv, and Conda are supported) in use
* The current Ruby environment (rvm and rbenv are supported) in use
* Last command exit code (only shown when the exit code is greater than 0)

## Configuration

This theme is pretty configurable, all the configuration is done by setting environment variables.

### User Information

By default, the username and hostname are shown, but you can change this behavior by setting the value of the following variable:

POWERLINE_PROMPT_USER_INFO_MODE="sudo"

For now, the only supported value is `sudo`, which hides the username and hostname, and shows an indicator when `sudo` has the credentials cached. Other values have no effect at this time.

### Clock Format

You can change the format using the following variable:

THEME_CLOCK_FORMAT="%H:%M:%S"

The time/date is printed by the `date` command, so refer to its man page to change the format.

### Segment Order

The contents of the prompt can be "reordered", all the "segments" (every piece of information) can take any place. The currently available segments are:

* battery
* clock
* cwd
* in_vim
* python_venv
* ruby
* scm
* user_info

A variables can be defined to set the order of the prompt segments:

POWERLINE_PROMPT="user_info scm python_venv ruby cwd"

The example values above are the current default values, but if you want to remove anything from the prompt, simply remove the "string" that represents the segment from the variable.
![Screenshot](./powerline-light.png?raw=true)
63 changes: 29 additions & 34 deletions themes/powerline-multiline/powerline-multiline.base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,58 @@
source "$OSH/themes/powerline/powerline.base.sh"

function __powerline_last_status_prompt {
[[ "$1" -ne 0 ]] && _omb_util_print "$(set_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${_omb_prompt_normal}"
(($1 != 0)) && _omb_util_print "$(set_color $LAST_STATUS_THEME_PROMPT_COLOR -) $1 $_omb_prompt_normal"
}

function __powerline_right_segment {
local OLD_IFS="${IFS}"; IFS="|"
local OLD_IFS=$IFS; IFS='|'
local params=( $1 )
IFS="${OLD_IFS}"
local separator_char="${POWERLINE_RIGHT_SEPARATOR}"
IFS=$OLD_IFS
local separator_char=$POWERLINE_RIGHT_SEPARATOR
local padding=2
local separator_color=""
local text_color=${params[2]:-"-"}
local text_color=${params[2]:-'-'}

if [[ "${SEGMENTS_AT_RIGHT}" -eq 0 ]]; then
separator_color="$(set_color ${params[1]} -)"
if ((SEGMENTS_AT_RIGHT == 0)); then
separator_color=$(set_color ${params[1]} -)
else
separator_color="$(set_color ${params[1]} ${LAST_SEGMENT_COLOR})"
(( padding += 1 ))
separator_color=$(set_color ${params[1]} $LAST_SEGMENT_COLOR)
((padding += 1))
fi
RIGHT_PROMPT+="${separator_color}${separator_char}${_omb_prompt_normal}$(set_color ${text_color} ${params[1]}) ${params[0]} ${_omb_prompt_normal}$(set_color - ${COLOR})${_omb_prompt_normal}"
RIGHT_PROMPT_LENGTH=$(( ${#params[0]} + RIGHT_PROMPT_LENGTH + padding ))
LAST_SEGMENT_COLOR="${params[1]}"
(( SEGMENTS_AT_RIGHT += 1 ))
RIGHT_PROMPT+="$separator_color$separator_char$_omb_prompt_normal$(set_color $text_color ${params[1]}) ${params[0]} $_omb_prompt_normal$(set_color - $COLOR)$_omb_prompt_normal"
RIGHT_PROMPT_LENGTH=$((${#params[0]} + RIGHT_PROMPT_LENGTH + padding))
LAST_SEGMENT_COLOR=${params[1]}
((SEGMENTS_AT_RIGHT += 1))
}

function __powerline_prompt_command {
local last_status="$?" ## always the first
local separator_char="${POWERLINE_LEFT_SEPARATOR}"
local last_status=$? ## always the first
local separator_char=$POWERLINE_LEFT_SEPARATOR
local move_cursor_rightmost='\033[500C'

LEFT_PROMPT=""
RIGHT_PROMPT=""
RIGHT_PROMPT_LENGTH=0
SEGMENTS_AT_LEFT=0
SEGMENTS_AT_RIGHT=0
LAST_SEGMENT_COLOR=""
local LEFT_PROMPT=""
local RIGHT_PROMPT=""
local RIGHT_PROMPT_LENGTH=0
local SEGMENTS_AT_LEFT=0
local SEGMENTS_AT_RIGHT=0
local LAST_SEGMENT_COLOR=""

## left prompt ##
for segment in $POWERLINE_LEFT_PROMPT; do
local info="$(__powerline_${segment}_prompt)"
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
local info=$(__powerline_"$segment"_prompt)
[[ $info ]] && __powerline_left_segment "$info"
done
[[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${separator_char}${_omb_prompt_normal}"
[[ $LEFT_PROMPT ]] && LEFT_PROMPT+=$(set_color ${LAST_SEGMENT_COLOR} -)${separator_char}${_omb_prompt_normal}

## right prompt ##
if [[ -n "${POWERLINE_RIGHT_PROMPT}" ]]; then
LEFT_PROMPT+="${move_cursor_rightmost}"
if [[ $POWERLINE_RIGHT_PROMPT ]]; then
LEFT_PROMPT+=$move_cursor_rightmost
for segment in $POWERLINE_RIGHT_PROMPT; do
local info="$(__powerline_${segment}_prompt)"
[[ -n "${info}" ]] && __powerline_right_segment "${info}"
local info=$(__powerline_"$segment"_prompt)
[[ $info ]] && __powerline_right_segment "$info"
done
LEFT_PROMPT+="\033[${RIGHT_PROMPT_LENGTH}D"
fi

PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n$(__powerline_last_status_prompt ${last_status})${PROMPT_CHAR} "

## cleanup ##
unset LAST_SEGMENT_COLOR \
LEFT_PROMPT RIGHT_PROMPT RIGHT_PROMPT_LENGTH \
SEGMENTS_AT_LEFT SEGMENTS_AT_RIGHT
PS1="$LEFT_PROMPT$RIGHT_PROMPT\n$(__powerline_last_status_prompt $last_status)$PROMPT_CHAR "
}
60 changes: 5 additions & 55 deletions themes/powerline-naked/README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,8 @@
# Powerline Theme
# Powerline Naked Theme

A colorful theme, where shows a lot information about your shell session.
A simple theme derived from the Powerline theme.

**IMPORTANT:** This theme requires that [a font with the Powerline symbols](https://github.com/powerline/fonts) needs to be used in your terminal emulator, otherwise the prompt won't be displayed correctly, i.e. some of the additional icons and characters will be missing. Please follow your operating system's instructions to install one of the fonts from the above link and select it in your terminal emulator.
This is based on the Powerline theme. Please see also [the documentation of the
powerline theme](../powerline/README.md).

## Provided Information

* Current path
* Current username and hostname
* Current time
* An indicator when connected by SSH
* An indicator when `sudo` has the credentials cached (see the `sudo` manpage for more info about this)
* An indicator when the current shell is inside the Vim editor
* Battery charging status (depends on the [../../plugins/battery/battery.plugin.sh](battery plugin))
* SCM Repository status (e.g. Git, SVN)
* The current Python environment (Virtualenv, venv, and Conda are supported) in use
* The current Ruby environment (rvm and rbenv are supported) in use
* Last command exit code (only shown when the exit code is greater than 0)

## Configuration

This theme is pretty configurable, all the configuration is done by setting environment variables.

### User Information

By default, the username and hostname are shown, but you can change this behavior by setting the value of the following variable:

POWERLINE_PROMPT_USER_INFO_MODE="sudo"

For now, the only supported value is `sudo`, which hides the username and hostname, and shows an indicator when `sudo` has the credentials cached. Other values have no effect at this time.

### Clock Format

You can change the format using the following variable:

THEME_CLOCK_FORMAT="%H:%M:%S"

The time/date is printed by the `date` command, so refer to its man page to change the format.

### Segment Order

The contents of the prompt can be "reordered", all the "segments" (every piece of information) can take any place. The currently available segments are:

* battery
* clock
* cwd
* in_vim
* python_venv
* ruby
* scm
* user_info

A variables can be defined to set the order of the prompt segments:

POWERLINE_PROMPT="user_info scm python_venv ruby cwd"

The example values above are the current default values, but if you want to remove anything from the prompt, simply remove the "string" that represents the segment from the variable.
![Screenshot](./powerline-naked-dark.png?raw=true)
12 changes: 6 additions & 6 deletions themes/powerline-naked/powerline-naked.base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
source "$OSH/themes/powerline/powerline.base.sh"

function __powerline_left_segment {
local OLD_IFS="${IFS}"; IFS="|"
local OLD_IFS=$IFS; IFS='|'
local params=( $1 )
IFS="${OLD_IFS}"
IFS=$OLD_IFS
local separator_char=""
local separator=""
local background_color=${params[2]:-"-"}
local background_color=${params[2]:-'-'}

if [[ "${SEGMENTS_AT_LEFT}" -gt 0 ]]; then
separator="${separator_char}"
if ((SEGMENTS_AT_LEFT > 0)); then
separator=$separator_char
fi
LEFT_PROMPT+="${separator}$(set_color ${params[1]} ${background_color}) ${params[0]} ${_omb_prompt_normal}"
(( SEGMENTS_AT_LEFT += 1 ))
((SEGMENTS_AT_LEFT += 1))
}
Loading

0 comments on commit 8cc21b7

Please sign in to comment.