From 47b1fb41e9b5009fbeee9bbbbc8e8dd4d68405a5 Mon Sep 17 00:00:00 2001 From: jjohnstondev Date: Thu, 19 Jan 2023 17:54:30 -0800 Subject: [PATCH] initial --- LICENSE | 21 ++++++++++++++++ README.md | 51 ++++++++++++++++++++++++++++++++++++++ actual_song.tmux | 27 ++++++++++++++++++++ scripts/get_now_playing.sh | 14 +++++++++++ scripts/shared.sh | 16 ++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100755 actual_song.tmux create mode 100755 scripts/get_now_playing.sh create mode 100644 scripts/shared.sh diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8a2bedd --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 abs3nt + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0cea9da --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Tmux Spotify-TUI plugin + +Plugin that shows current playing song with [gospt](https://gitea.asdf.cafe/abs3nt/gospt). + +![Screenshot](https://user-images.githubusercontent.com/86447830/213586650-1a1d67c6-c029-4724-b8c2-f027deb16bb4.png) + +### Usage + +```tmux.conf +set -g status-right '#{now_playing}' +``` + +### Installation with Tmux Plugin Manager (Recommended) + +Add plugin to the list of TPM plugins: + +```tmux.conf +set -g @plugin 'abs3ntdev/tmux-gospt' +``` + +Press prefix + I to install it. + +### Manual Installation + +Clone the repo: + +```bash +$ git clone https://github.com/abs3ntdev/tmux-gospt ~/clone/path +``` + +Add this line to your .tmux.conf: + +```tmux.conf +run-shell ~/clone/path/actual_song.tmux +``` + +Reload TMUX environment with: + +```bash +$ tmux source-file ~/.tmux.conf +``` + +or: + +Press prefix + R to install it. + +___ + +### License + +[MIT](LICENSE) diff --git a/actual_song.tmux b/actual_song.tmux new file mode 100755 index 0000000..9a1a646 --- /dev/null +++ b/actual_song.tmux @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +now_playing="#($CURRENT_DIR/scripts/get_now_playing.sh)" +now_playing_interpolation_string="\#{now_playing}" + +source $CURRENT_DIR/scripts/shared.sh + +do_interpolation() { + local string="$1" + local interpolated="${string/$now_playing_interpolation_string/$now_playing}" + echo "$interpolated" +} + +update_tmux_option() { + local option="$1" + local option_value="$(get_tmux_option "$option")" + local new_option_value="$(do_interpolation "$option_value")" + set_tmux_option "$option" "$new_option_value" +} + +main() { + update_tmux_option "status-right" + update_tmux_option "status-left" +} +main diff --git a/scripts/get_now_playing.sh b/scripts/get_now_playing.sh new file mode 100755 index 0000000..13a6bfb --- /dev/null +++ b/scripts/get_now_playing.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -euo pipefail + +song="$(gospt nowplaying)" + +if [[ $song =~ ['⏸'] ]]; then + + echo $song | sed 's/[⏸▶]//g' + +else + + echo $song | sed 's/[⏸▶]//g' + +fi diff --git a/scripts/shared.sh b/scripts/shared.sh new file mode 100644 index 0000000..eba621f --- /dev/null +++ b/scripts/shared.sh @@ -0,0 +1,16 @@ +get_tmux_option() { + local option=$1 + local default_value=$2 + local option_value=$(tmux show-option -gqv "$option") + if [ -z "$option_value" ]; then + echo "$default_value" + else + echo "$option_value" + fi +} + +set_tmux_option() { + local option="$1" + local value="$2" + tmux set-option -gq "$option" "$value" +}