Skip to content

Commit

Permalink
feat: pre-commit and Actions workflow (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stealthii authored Apr 12, 2024
1 parent 0d8406e commit d3d484e
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
- [ ] Fixes #...
- [ ] Fixes #...

## Additional informations
## Additional information

None.
16 changes: 16 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: pre-commit

on:
pull_request:
push:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: pre-commit/action@v3.0.1
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/pecigonzalo/pre-commit-shfmt
rev: v2.1.0
hooks:
- id: shell-fmt-go
args:
- -w
- -s
- -l
- -i
- "2"
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This is a very opinionated project, as I am a Tech Lead, this theme is very deve
### Nerd Fonts

This theme requires the use of a patched font with Nerd Font. Ensure your terminal is set to use one before installing this theme. Any patched font will do. See
[`nerdfonts.com`](https://www.nerdfonts.com/) for more informations.
[`nerdfonts.com`](https://www.nerdfonts.com/) for more information.

### Noto Fonts

Expand Down Expand Up @@ -166,5 +166,14 @@ Legacy tokyo-night

![Snap 4](snaps/l01.png)

## Contributing

This project is open to contributions. Please feel free to open an issue or a pull request.

Ensure your editor is configured appropriately to consider the provided `.editorconfig` file.
[pre-commit] hooks are also provided to ensure code consistency, and will be run against any raised PRs.


[cmus]: https://cmus.github.io/
[nowplaying-cli]: https://github.com/kirtan-shah/nowplaying-cli
[pre-commit]: https://pre-commit.com/
34 changes: 15 additions & 19 deletions src/cmus-tmux-statusbar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,35 @@ BG_COLOR="#1F2335"
BG_BAR="#15161e"
TIME_COLOR="#414868"

if [[ $1 =~ ^[[:digit:]]+$ ]]; then
MAX_TITLE_WIDTH=20
else
MAX_TITLE_WIDTH=$(($(tmux display -p '#{window_width}' 2> /dev/null || echo 120) - 130))
if [[ $1 =~ ^[[:digit:]]+$ ]]; then
MAX_TITLE_WIDTH=20
else
MAX_TITLE_WIDTH=$(($(tmux display -p '#{window_width}' 2>/dev/null || echo 120) - 130))
fi

MAX_TITLE_WIDTH=25

if cmus-remote -Q > /dev/null 2> /dev/null; then
if cmus-remote -Q >/dev/null 2>/dev/null; then
CMUS_STATUS=$(cmus-remote -Q)
STATUS=$(echo "$CMUS_STATUS" | grep status | head -n 1 | cut -d' ' -f2-)
ARTIST=$(echo "$CMUS_STATUS" | grep 'tag artist' | head -n 1 | cut -d' ' -f3-)
TITLE=$(echo "$CMUS_STATUS" | grep 'tag title' | cut -d' ' -f3-)
DURATION=$(echo "$CMUS_STATUS" | grep 'duration' | cut -d' ' -f2-)
POSITION=$(echo "$CMUS_STATUS" | grep 'position' | cut -d' ' -f2-)

P_MIN=$(printf '%02d' $((POSITION / 60)))
P_SEC=$(printf '%02d' $((POSITION % 60)))

P_MIN=`printf '%02d' $(($POSITION / 60))`
P_SEC=`printf '%02d' $(($POSITION % 60))`

D_MIN=`printf '%02d' $(($DURATION / 60))`
D_SEC=`printf '%02d' $(($DURATION % 60))`
D_MIN=$(printf '%02d' $((DURATION / 60)))
D_SEC=$(printf '%02d' $((DURATION % 60)))
TIME="[$P_MIN:$P_SEC / $D_MIN:$D_SEC]"



if [ "$D_SEC" = "-1" ]; then
TIME="[ $P_MIN:$P_SEC]"
fi

if [ -n "$TITLE" ]; then
if [ "$STATUS" = "playing" ]; then
if [ -n "$TITLE" ]; then
if [ "$STATUS" = "playing" ]; then
PLAY_STATE="$OUTPUT"
else
PLAY_STATE="$OUTPUT"
Expand All @@ -50,14 +47,13 @@ if cmus-remote -Q > /dev/null 2> /dev/null; then
fi
fi

if [ "${#OUTPUT}" -ge $MAX_TITLE_WIDTH ]; then
if [ "${#OUTPUT}" -ge $MAX_TITLE_WIDTH ]; then
OUTPUT="$PLAY_STATE ${TITLE:0:$MAX_TITLE_WIDTH-1}"
# Remove trailing spaces
OUTPUT="${OUTPUT%"${OUTPUT##*[![:space:]]}"}"
fi

if [ -z "$OUTPUT" ]
then
if [ -z "$OUTPUT" ]; then
echo "$OUTPUT #[fg=green,bg=default]"
else
OUT=" $OUTPUT $TIME "
Expand All @@ -69,9 +65,9 @@ else
O=" $OUTPUT"

if [ $PROGRESS -le $TIME_INDEX ]; then
echo "#[nobold,fg=$BG_COLOR,bg=$ACCENT_COLOR]${O:0:$PROGRESS}#[fg=$ACCENT_COLOR,bg=$BG_BAR]${O:$PROGRESS:$TIME_INDEX} #[fg=$TIME_COLOR,bg=$BG_BAR]$TIME "
echo "#[nobold,fg=$BG_COLOR,bg=$ACCENT_COLOR]${O:0:PROGRESS}#[fg=$ACCENT_COLOR,bg=$BG_BAR]${O:PROGRESS:TIME_INDEX} #[fg=$TIME_COLOR,bg=$BG_BAR]$TIME "
else
DIFF=$((PROGRESS - TIME_INDEX))
echo "#[nobold,fg=$BG_COLOR,bg=$ACCENT_COLOR]${O:0:$TIME_INDEX} #[fg=$BG_BAR,bg=$ACCENT_COLOR]${OUT:$TIME_INDEX:$DIFF}#[fg=$TIME_COLOR,bg=$BG_BAR]${OUT:$PROGRESS}"
echo "#[nobold,fg=$BG_COLOR,bg=$ACCENT_COLOR]${O:0:TIME_INDEX} #[fg=$BG_BAR,bg=$ACCENT_COLOR]${OUT:TIME_INDEX:DIFF}#[fg=$TIME_COLOR,bg=$BG_BAR]${OUT:PROGRESS}"
fi
fi
4 changes: 2 additions & 2 deletions src/custom-number.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if [ "$FORMAT" = "roman" ] && [ ${#ID} -gt 1 ]; then
continue
else
for ((i = 0; i < ${#ID}; i++)); do
DIGIT=${ID:$i:1}
echo -n "${format:$DIGIT:1}"
DIGIT=${ID:i:1}
echo -n "${format:DIGIT:1}"
done
fi
18 changes: 9 additions & 9 deletions src/datetime-widget.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Grab global variable for showing datetime widget, only hide if explicitly disabled
SHOW_DATETIME=$(tmux show-option -gv @tokyo-night-tmux_show_datetime 2>/dev/null)
if [[ "$SHOW_DATETIME" == "0" ]]; then
if [[ $SHOW_DATETIME == "0" ]]; then
exit 0
fi

Expand All @@ -13,26 +13,26 @@ time_format=$(tmux show-option -gv @tokyo-night-tmux_time_format 2>/dev/null)
date_string=""
time_string=""

if [[ "$date_format" == "YMD" ]]; then
if [[ $date_format == "YMD" ]]; then
# Year Month Day date format
date_string="%Y-%m-%d"
elif [[ "$date_format" == "MDY" ]]; then
elif [[ $date_format == "MDY" ]]; then
# Month Day Year date format
date_string="%m-%d-%Y"
elif [[ "$date_format" == "DMY" ]]; then
elif [[ $date_format == "DMY" ]]; then
# Day Month Year date format
date_string="%d-%m-%Y"
else
# Default to YMD date format if not specified
date_string="%Y-%m-%d"
fi

if [[ "$time_format" == "12H" ]]; then
# 12-hour format with AM/PM
time_string="%I:%M %p"
if [[ $time_format == "12H" ]]; then
# 12-hour format with AM/PM
time_string="%I:%M %p"
else
# Default to 24-hour format if not specified
time_string="%H:%M"
# Default to 24-hour format if not specified
time_string="%H:%M"
fi

echo "#[fg=#a9b1d6,bg=#24283B] $date_string #[]❬ $time_string "
63 changes: 33 additions & 30 deletions src/git-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cd $1
RESET="#[fg=brightwhite,bg=#15161e,nobold,noitalics,nounderscore,nodim]"
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
STATUS=$(git status --porcelain 2>/dev/null| egrep "^(M| M)" | wc -l)
STATUS=$(git status --porcelain 2>/dev/null | egrep "^(M| M)" | wc -l)
BRANCH_SIZE=${#BRANCH}

SYNC_MODE=0
Expand Down Expand Up @@ -47,41 +47,44 @@ else
STATUS_UNTRACKED=""
fi


# Determine repository sync status
if [[ $SYNC_MODE == 0 ]]; then
NEED_PUSH=$(git log @{push}.. | wc -l | bc)
if [[ $NEED_PUSH > 0 ]]; then
SYNC_MODE=2
else
LAST_FETCH=$(stat -c %Y .git/FETCH_HEAD | bc)
NOW=$(date +%s | bc)

# if 5 minutes have passed since the last fetch
if [[ $((NOW-LAST_FETCH)) -gt 300 ]]; then
git fetch --atomic origin --negotiation-tip=HEAD
fi

REMOTE_DIFF="$(git diff --shortstat $(git rev-parse --abbrev-ref HEAD) origin/$(git rev-parse --abbrev-ref HEAD) 2>/dev/null | wc -l | bc)"
if [[ $REMOTE_DIFF > 0 ]]; then
SYNC_MODE=3
fi
NEED_PUSH=$(git log @{push}.. | wc -l | bc)
if [[ $NEED_PUSH > 0 ]]; then
SYNC_MODE=2
else
LAST_FETCH=$(stat -c %Y .git/FETCH_HEAD | bc)
NOW=$(date +%s | bc)

# if 5 minutes have passed since the last fetch
if [[ $((NOW - LAST_FETCH)) -gt 300 ]]; then
git fetch --atomic origin --negotiation-tip=HEAD
fi

REMOTE_DIFF="$(git diff --shortstat $(git rev-parse --abbrev-ref HEAD) origin/$(git rev-parse --abbrev-ref HEAD) 2>/dev/null | wc -l | bc)"
if [[ $REMOTE_DIFF > 0 ]]; then
SYNC_MODE=3
fi
fi
fi

if [[ $SYNC_MODE > 0 ]]; then
case "$SYNC_MODE" in
1) REMOTE_STATUS="$RESET#[bg=#15161e,fg=#ff9e64,bold]▒ 󱓎"
;;
2) REMOTE_STATUS="$RESET#[bg=#15161e,fg=#f7768e,bold]▒ 󰛃"
;;
3) REMOTE_STATUS="$RESET#[bg=#15161e,fg=#bb9af7,bold]▒ 󰛀"
;;
*) echo default
;;
esac
else
REMOTE_STATUS="$RESET#[fg=#73daca,bg=#15161e,bold]▒ "
case "$SYNC_MODE" in
1)
REMOTE_STATUS="$RESET#[bg=#15161e,fg=#ff9e64,bold]▒ 󱓎"
;;
2)
REMOTE_STATUS="$RESET#[bg=#15161e,fg=#f7768e,bold]▒ 󰛃"
;;
3)
REMOTE_STATUS="$RESET#[bg=#15161e,fg=#bb9af7,bold]▒ 󰛀"
;;
*)
echo default
;;
esac
else
REMOTE_STATUS="$RESET#[fg=#73daca,bg=#15161e,bold]▒ "
fi

if test "$BRANCH" != ""; then
Expand Down
39 changes: 19 additions & 20 deletions src/music-tmux-statusbar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# Check the global value
SHOW_MUSIC=$(tmux show-option -gv @tokyo-night-tmux_show_music)
if [ "$SHOW_MUSIC" != "1" ]; then
exit 0
exit 0
fi

# Value parser for nowplaying-cli
parse_npcli_value() {
echo "$NPCLI_STATUS" | grep "$1" | awk -F '= ' '{print $2}' | tr -d '";'
echo "$NPCLI_STATUS" | grep "$1" | awk -F '= ' '{print $2}' | tr -d '";'
}

ACCENT_COLOR="#7aa2f7"
Expand All @@ -17,14 +17,14 @@ BG_COLOR="#1F2335"
BG_BAR="#15161e"
TIME_COLOR="#414868"

if [[ $1 =~ ^[[:digit:]]+$ ]]; then
MAX_TITLE_WIDTH=$1
else
MAX_TITLE_WIDTH=$(($(tmux display -p '#{window_width}' 2> /dev/null || echo 120) - 90))
if [[ $1 =~ ^[[:digit:]]+$ ]]; then
MAX_TITLE_WIDTH=$1
else
MAX_TITLE_WIDTH=$(($(tmux display -p '#{window_width}' 2>/dev/null || echo 120) - 90))
fi

# playerctl
if command -v playerctl > /dev/null; then
if command -v playerctl >/dev/null; then
PLAYER_STATUS=$(playerctl -a metadata --format "{{status}};{{mpris:length}};{{position}};{{title}}" | grep -m1 "Playing")
STATUS="playing"

Expand All @@ -48,7 +48,7 @@ if command -v playerctl > /dev/null; then
fi

# nowplaying-cli
elif command -v nowplaying-cli > /dev/null; then
elif command -v nowplaying-cli >/dev/null; then
NPCLI_STATUS=$(nowplaying-cli get-raw)
if [ "$(parse_npcli_value PlaybackRate)" = "1" ]; then
STATUS="playing"
Expand Down Expand Up @@ -79,12 +79,12 @@ elif command -v nowplaying-cli > /dev/null; then
fi
# If POSITION, calculate the progress bar
if [ -n "$POSITION" ]; then
P_MIN=`printf '%02d' $(($POSITION / 60))`
P_SEC=`printf '%02d' $(($POSITION % 60))`
P_MIN=$(printf '%02d' $((POSITION / 60)))
P_SEC=$(printf '%02d' $((POSITION % 60)))
fi
if [ -n "$DURATION" ]; then
D_MIN=`printf '%02d' $(($DURATION / 60))`
D_SEC=`printf '%02d' $(($DURATION % 60))`
D_MIN=$(printf '%02d' $((DURATION / 60)))
D_SEC=$(printf '%02d' $((DURATION % 60)))
fi
if [ -n "$DURATION" ] && [ -n "$POSITION" ]; then
TIME="[$P_MIN:$P_SEC / $D_MIN:$D_SEC]"
Expand All @@ -94,31 +94,30 @@ if [ -n "$DURATION" ] && [ -n "$POSITION" ]; then
else
TIME="[--:--]"
fi
if [ -n "$TITLE" ]; then
if [ "$STATUS" = "playing" ]; then
if [ -n "$TITLE" ]; then
if [ "$STATUS" = "playing" ]; then
PLAY_STATE="$OUTPUT"
else
PLAY_STATE="󰏤$OUTPUT"
fi
OUTPUT="$PLAY_STATE $TITLE"

# Only show the song title if we are over $MAX_TITLE_WIDTH characters
if [ "${#OUTPUT}" -ge $MAX_TITLE_WIDTH ]; then
if [ "${#OUTPUT}" -ge $MAX_TITLE_WIDTH ]; then
OUTPUT="$PLAY_STATE ${TITLE:0:$MAX_TITLE_WIDTH-1}"
fi
else
OUTPUT=''
fi

MAX_TITLE_WIDTH=25
if [ "${#OUTPUT}" -ge $MAX_TITLE_WIDTH ]; then
if [ "${#OUTPUT}" -ge $MAX_TITLE_WIDTH ]; then
OUTPUT="$PLAY_STATE ${TITLE:0:$MAX_TITLE_WIDTH-1}"
# Remove trailing spaces
OUTPUT="${OUTPUT%"${OUTPUT##*[![:space:]]}"}"
fi

if [ -z "$OUTPUT" ]
then
if [ -z "$OUTPUT" ]; then
echo "$OUTPUT #[fg=green,bg=default]"
else
OUT=" $OUTPUT $TIME "
Expand All @@ -130,9 +129,9 @@ else
O=" $OUTPUT"

if [ $PROGRESS -le $TIME_INDEX ]; then
echo "#[nobold,fg=$BG_COLOR,bg=$ACCENT_COLOR]${O:0:$PROGRESS}#[fg=$ACCENT_COLOR,bg=$BG_BAR]${O:$PROGRESS:$TIME_INDEX} #[fg=$TIME_COLOR,bg=$BG_BAR]$TIME "
echo "#[nobold,fg=$BG_COLOR,bg=$ACCENT_COLOR]${O:0:PROGRESS}#[fg=$ACCENT_COLOR,bg=$BG_BAR]${O:PROGRESS:TIME_INDEX} #[fg=$TIME_COLOR,bg=$BG_BAR]$TIME "
else
DIFF=$((PROGRESS - TIME_INDEX))
echo "#[nobold,fg=$BG_COLOR,bg=$ACCENT_COLOR]${O:0:$TIME_INDEX} #[fg=$BG_BAR,bg=$ACCENT_COLOR]${OUT:$TIME_INDEX:$DIFF}#[fg=$TIME_COLOR,bg=$BG_BAR]${OUT:$PROGRESS}"
echo "#[nobold,fg=$BG_COLOR,bg=$ACCENT_COLOR]${O:0:TIME_INDEX} #[fg=$BG_BAR,bg=$ACCENT_COLOR]${OUT:TIME_INDEX:DIFF}#[fg=$TIME_COLOR,bg=$BG_BAR]${OUT:PROGRESS}"
fi
fi
Loading

0 comments on commit d3d484e

Please sign in to comment.