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

Cleanup #421

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/linter-full.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Lint Code Base

on:
Expand All @@ -20,7 +21,8 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
# Full git history is needed to get a proper list of changed
# files within `super-linter`
fetch-depth: 0
- name: Lint Code Base
uses: super-linter/[email protected]
Expand All @@ -30,6 +32,5 @@ jobs:
VALIDATE_BASH_EXEC: false
VALIDATE_CPP: false
VALIDATE_CLANG_FORMAT: false
VALIDATE_SHELL_SHFMT: false
VALIDATE_PYTHON_PYLINT: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 3 additions & 2 deletions .github/workflows/linter-pr.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Lint Pull Request

on:
Expand All @@ -20,7 +21,8 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
# Full git history is needed to get a proper list of changed
# files within `super-linter`
fetch-depth: 0
- name: Lint Code Base
uses: super-linter/super-linter@v6
Expand All @@ -30,6 +32,5 @@ jobs:
VALIDATE_BASH_EXEC: false
VALIDATE_CPP: false
VALIDATE_CLANG_FORMAT: false
VALIDATE_SHELL_SHFMT: false
VALIDATE_PYTHON_PYLINT: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: "Close stale issues and PRs"
on:
workflow_dispatch:
Expand Down
6 changes: 3 additions & 3 deletions color_palette.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# Idea from http://superuser.com/questions/285381/how-does-the-tmux-color-palette-work

for i in $(seq 0 8 255); do
for j in $(seq "$i" $(( i + 7 ))); do
for _unused in $(seq 1 $(( 7 - ${#j} ))); do
for j in $(seq "$i" $((i + 7))); do
for _unused in $(seq 1 $((7 - ${#j}))); do
echo -n " "
done
echo -en "\x1b[38;5;${j}mcolour${j}"
[[ $(( j % 8 )) != 7 ]] && echo -n " "
[[ $((j % 8)) != 7 ]] && echo -n " "
done
echo
done
4 changes: 2 additions & 2 deletions config/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Other settings and helper functions.

debug_mode_enabled() {
[ -n "$TMUX_POWERLINE_DEBUG_MODE_ENABLED" ] && [ "$TMUX_POWERLINE_DEBUG_MODE_ENABLED" != "false" ];
[ -n "$TMUX_POWERLINE_DEBUG_MODE_ENABLED" ] && [ "$TMUX_POWERLINE_DEBUG_MODE_ENABLED" != "false" ]
}

patched_font_in_use() {
[ -z "$TMUX_POWERLINE_PATCHED_FONT_IN_USE" ] || [ "$TMUX_POWERLINE_PATCHED_FONT_IN_USE" != "false" ];
[ -z "$TMUX_POWERLINE_PATCHED_FONT_IN_USE" ] || [ "$TMUX_POWERLINE_PATCHED_FONT_IN_USE" != "false" ]
}
10 changes: 5 additions & 5 deletions config/shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ ostype() { echo "$OSTYPE" | tr '[:upper:]' '[:lower:]'; }
export SHELL_PLATFORM='unknown'

case "$(ostype)" in
*'linux'* ) SHELL_PLATFORM='linux' ;;
*'darwin'* ) SHELL_PLATFORM='osx' ;;
*'bsd'* ) SHELL_PLATFORM='bsd' ;;
*'linux'*) SHELL_PLATFORM='linux' ;;
*'darwin'*) SHELL_PLATFORM='osx' ;;
*'bsd'*) SHELL_PLATFORM='bsd' ;;
esac

shell_is_linux() { [[ $SHELL_PLATFORM == 'linux' || $SHELL_PLATFORM == 'bsd' ]]; }
shell_is_osx() { [[ $SHELL_PLATFORM == 'osx' ]]; }
shell_is_bsd() { [[ $SHELL_PLATFORM == 'bsd' || $SHELL_PLATFORM == 'osx' ]]; }
shell_is_osx() { [[ $SHELL_PLATFORM == 'osx' ]]; }
shell_is_bsd() { [[ $SHELL_PLATFORM == 'bsd' || $SHELL_PLATFORM == 'osx' ]]; }

export -f shell_is_linux
export -f shell_is_osx
Expand Down
2 changes: 1 addition & 1 deletion generate_config.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Generate default config file.

TMUX_POWERLINE_DIR_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TMUX_POWERLINE_DIR_HOME="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export TMUX_POWERLINE_DIR_HOME

source "${TMUX_POWERLINE_DIR_HOME}/config/paths.sh"
Expand Down
4 changes: 2 additions & 2 deletions lib/arg_processing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

check_arg_segment() {
local segment="$1"
if ! [[ "$segment" == "left" || "$segment" == "right" || "$segment" == "window-current-format" || "$segment" == "window-format" ]]; then
if ! [[ "$segment" == "left" || "$segment" == "right" || "$segment" == "window-current-format" || "$segment" == "window-format" ]]; then
echo "Argument must be the side to handle {left, right}, or {window-current-format, window-format}, not \"${segment}\"."
exit 1
exit 1
fi
}
12 changes: 6 additions & 6 deletions lib/colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ __normalize_color() {
local result

case "$input" in
[0-9]|[0-9][0-9]|[0-9][0-9][0-9]) # handle 1 to 3 digits
result="colour$input"
;;
*) # Catch-all
result=$input
;;
[0-9] | [0-9][0-9] | [0-9][0-9][0-9]) # handle 1 to 3 digits
result="colour$input"
;;
*) # Catch-all
result=$input
;;
esac

echo -n "$result"
Expand Down
8 changes: 3 additions & 5 deletions lib/config_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,10 @@ process_settings() {

export TMUX_POWERLINE_STATUS_STYLE="fg=$fg_color,bg=$bg_color"
fi


}

generate_default_config() {
read -r -d '' config_contents << EORC
read -r -d '' config_contents <<EORC
# Default configuration file for tmux-powerline.
# Modeline {
# vi: foldmarker={,} foldmethod=marker foldlevel=0 tabstop=4 filetype=sh
Expand Down Expand Up @@ -142,13 +140,13 @@ EORC
fi
done

echo -e "$config_contents" > "$TMUX_POWERLINE_CONFIG_FILE_DEFAULT"
echo -e "$config_contents" >"$TMUX_POWERLINE_CONFIG_FILE_DEFAULT"
echo "Default configuration file generated to: ${TMUX_POWERLINE_CONFIG_FILE_DEFAULT}"
echo "Copy/move it to \"${TMUX_POWERLINE_CONFIG_FILE}\" and make your changes."
}

__read_config_file() {
if [ -f "$TMUX_POWERLINE_CONFIG_FILE" ]; then
if [ -f "$TMUX_POWERLINE_CONFIG_FILE" ]; then
# shellcheck disable=SC1090
source "$TMUX_POWERLINE_CONFIG_FILE"
fi
Expand Down
2 changes: 1 addition & 1 deletion lib/headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Source all needed libs and helpers, kind of like a main.h.

if [ -z "$TMUX_POWERLINE_DIR_HOME" ]; then
lib_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
lib_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TMUX_POWERLINE_DIR_HOME="$(dirname "$lib_dir")" # step up to parent dir.

export TMUX_POWERLINE_DIR_HOME
Expand Down
2 changes: 1 addition & 1 deletion lib/muting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# In all cases $1 is the side to be muted (eg left/right).

powerline_muted() {
[ -e "$(__powerline_mute_file "$1")" ];
[ -e "$(__powerline_mute_file "$1")" ]
}

toggle_powerline_mute_status() {
Expand Down
70 changes: 34 additions & 36 deletions lib/powerline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ print_powerline_side() {
print_powerline_window_status_current_format() {
if [ -z "$TMUX_POWERLINE_WINDOW_STATUS_CURRENT" ]; then
TMUX_POWERLINE_WINDOW_STATUS_CURRENT=(
"#[$(format inverse)]" \
"$TMUX_POWERLINE_DEFAULT_LEFTSIDE_SEPARATOR" \
" #I#F " \
"$TMUX_POWERLINE_SEPARATOR_RIGHT_THIN" \
" #W " \
"#[$(format regular)]" \
"#[$(format inverse)]"
"$TMUX_POWERLINE_DEFAULT_LEFTSIDE_SEPARATOR"
" #I#F "
"$TMUX_POWERLINE_SEPARATOR_RIGHT_THIN"
" #W "
"#[$(format regular)]"
"$TMUX_POWERLINE_DEFAULT_LEFTSIDE_SEPARATOR"
)
fi
Expand All @@ -38,9 +38,9 @@ print_powerline_window_status_current_format() {
print_powerline_window_status_format() {
if [ -z "$TMUX_POWERLINE_WINDOW_STATUS_FORMAT" ]; then
TMUX_POWERLINE_WINDOW_STATUS_FORMAT=(
"#[$(format regular)]" \
" #I#{?window_flags,#F, } " \
"$TMUX_POWERLINE_SEPARATOR_RIGHT_THIN" \
"#[$(format regular)]"
" #I#{?window_flags,#F, } "
"$TMUX_POWERLINE_SEPARATOR_RIGHT_THIN"
" #W "
)
fi
Expand All @@ -57,31 +57,30 @@ format() {
fg_color=$(__normalize_color "$TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR")

case $type in
inverse)
echo "fg=$bg_color,bg=$fg_color,nobold,noitalics,nounderscore"
;;
regular)
echo "fg=$fg_color,bg=$bg_color,nobold,noitalics,nounderscore"
;;
*)
;;
inverse)
echo "fg=$bg_color,bg=$fg_color,nobold,noitalics,nounderscore"
;;
regular)
echo "fg=$fg_color,bg=$bg_color,nobold,noitalics,nounderscore"
;;
*) ;;
esac
}

__process_segment_defaults() {
# shellcheck disable=SC2154 # disable until we found a better solution for eval input_segments
for segment_index in "${!input_segments[@]}"; do
local input_segment
read -r -a input_segment <<< "${input_segments[segment_index]}"
read -r -a input_segment <<<"${input_segments[segment_index]}"
eval "local default_separator=\$TMUX_POWERLINE_DEFAULT_${upper_side}SIDE_SEPARATOR"

powerline_segment_with_defaults=(
"${input_segment[0]:-no_script}" \
"${input_segment[1]:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}" \
"${input_segment[2]:-$TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR}" \
"${input_segment[3]:-$default_separator}" \
"${input_segment[6]:-$spacing_disable}" \
"${input_segment[7]:-$separator_disable}" \
"${input_segment[0]:-no_script}"
"${input_segment[1]:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}"
"${input_segment[2]:-$TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR}"
"${input_segment[3]:-$default_separator}"
"${input_segment[6]:-$spacing_disable}"
"${input_segment[7]:-$separator_disable}"
)

powerline_segments[segment_index]="${powerline_segment_with_defaults[*]}"
Expand All @@ -91,9 +90,9 @@ __process_segment_defaults() {
__process_scripts() {
for segment_index in "${!powerline_segments[@]}"; do
local powerline_segment
read -r -a powerline_segment <<< "${powerline_segments[segment_index]}"
read -r -a powerline_segment <<<"${powerline_segments[segment_index]}"

if [ -n "$TMUX_POWERLINE_DIR_USER_SEGMENTS" ] && [ -f "$TMUX_POWERLINE_DIR_USER_SEGMENTS/${powerline_segment[0]}.sh" ] ; then
if [ -n "$TMUX_POWERLINE_DIR_USER_SEGMENTS" ] && [ -f "$TMUX_POWERLINE_DIR_USER_SEGMENTS/${powerline_segment[0]}.sh" ]; then
local script="$TMUX_POWERLINE_DIR_USER_SEGMENTS/${powerline_segment[0]}.sh"
else
local script="$TMUX_POWERLINE_DIR_SEGMENTS/${powerline_segment[0]}.sh"
Expand All @@ -109,7 +108,7 @@ __process_scripts() {
local exit_code="$?"
unset -f run_segment

if [ "$exit_code" -ne 0 ] && debug_mode_enabled ; then
if [ "$exit_code" -ne 0 ] && debug_mode_enabled; then
local seg_name="${script##*/}"
echo "Segment '${seg_name}' exited with code ${exit_code}. Aborting."
exit 1
Expand All @@ -134,14 +133,14 @@ __process_scripts() {
__process_colors() {
for segment_index in "${!powerline_segments[@]}"; do
local powerline_segment
read -r -a powerline_segment <<< "${powerline_segments[segment_index]}"
read -r -a powerline_segment <<<"${powerline_segments[segment_index]}"
local separator_enable=${powerline_segment[5]}
# Find the next segment that produces content (i.e. skip empty segments).
for next_segment_index in $(eval echo "{$((segment_index + 1))..${#powerline_segments}}") ; do
for next_segment_index in $(eval echo "{$((segment_index + 1))..${#powerline_segments}}"); do
[[ -n ${powerline_segments[next_segment_index]} ]] && break
done
local next_segment
read -r -a next_segment <<< "${powerline_segments[next_segment_index]}"
read -r -a next_segment <<<"${powerline_segments[next_segment_index]}"

if [ "$side" == 'left' ]; then
powerline_segment[4]=${next_segment[1]:-$TMUX_POWERLINE_DEFAULT_BACKGROUND_COLOR}
Expand All @@ -165,7 +164,7 @@ __process_colors() {
__process_powerline() {
for segment_index in "${!powerline_segments[@]}"; do
local powerline_segment
read -r -a powerline_segment <<< "${powerline_segments[segment_index]}"
read -r -a powerline_segment <<<"${powerline_segments[segment_index]}"

local background_color=${powerline_segment[1]}
local foreground_color=${powerline_segment[2]}
Expand All @@ -188,7 +187,7 @@ __print_left_segment() {
local separator_disable=$7

__print_colored_content "$content" "$content_background_color" "$content_foreground_color"
if [ ! "$separator_disable" == "separator_disable" ] ; then
if [ ! "$separator_disable" == "separator_disable" ]; then
__print_colored_content "$separator" "$separator_background_color" "$separator_foreground_color"
fi
}
Expand All @@ -202,19 +201,18 @@ __print_right_segment() {
local separator_foreground_color=$6
local separator_disable=$7

if [ ! "$separator_disable" == "separator_disable" ] ; then
if [ ! "$separator_disable" == "separator_disable" ]; then
__print_colored_content "$separator" "$separator_background_color" "$separator_foreground_color"
fi
__print_colored_content "$content" "$content_background_color" "$content_foreground_color"
}

__segment_separator_is_thin() {
[[ ${powerline_segment[3]} == "$TMUX_POWERLINE_SEPARATOR_LEFT_THIN" || \
${powerline_segment[3]} == "$TMUX_POWERLINE_SEPARATOR_RIGHT_THIN" ]];
[[ ${powerline_segment[3]} == "$TMUX_POWERLINE_SEPARATOR_LEFT_THIN" || ${powerline_segment[3]} == "$TMUX_POWERLINE_SEPARATOR_RIGHT_THIN" ]]
}

__check_platform() {
if [ "$SHELL_PLATFORM" == "unknown" ] && debug_mode_enabled; then
echo "Unknown platform; modify config/shell.sh" >&2
echo "Unknown platform; modify config/shell.sh" >&2
fi
}
12 changes: 6 additions & 6 deletions lib/text_roll.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
# arg4: mode to fill {"space", "repeat"}
# arg5: repeat separator
roll_text() {
local text="$1" # Text to print
local text="$1" # Text to print

if [ -z "$text" ]; then
return;
return
fi

local max_len="10" # Default max length.
local max_len="10" # Default max length.

if [ -n "$2" ]; then
max_len="$2"
fi

local speed="1" # Default roll speed in chars per second.
local speed="1" # Default roll speed in chars per second.

if [ -n "$3" ]; then
speed="$3"
Expand Down Expand Up @@ -60,13 +60,13 @@ roll_text() {
# Truncate text on time-based offset
text=${text:offset}

# Ensure text is not longer than max_len
# Ensure text is not longer than max_len
text=${text:0:max_len}

# Get fill count by substracting length of current text from max_len
local fill_count=$((max_len - ${#text}))

for ((index=0; index < fill_count; index++)); do
for ((index = 0; index < fill_count; index++)); do
if [ "$fill_mode" = "repeat" ]; then
text="${text}${repeat:index:1}"
elif [ "$fill_mode" = "space" ] || :; then
Expand Down
Loading