├── README.md ├── music.tmux ├── screenshots └── spotify-status.png └── scripts ├── album.sh ├── artist.sh ├── helpers.sh ├── status.sh └── track.sh /README.md: -------------------------------------------------------------------------------- 1 | # Tmux Spotify Plugin 2 | 3 | Tmux plugin that shows the current music status for Spotify, Apple Music, or iTunes in your statusline. 4 | 5 | Introduces the following new status variables: 6 | 7 | * `#{music_status}` 8 | * `#{artist}` 9 | * `#{album}` 10 | * `#{track}` 11 | 12 | ### Usage 13 | 14 | The following interpolations are made available for your statusline: 15 | 16 | * `#{music_status}` - Spotify status icons 17 | * `#{artist}` - Current artist 18 | * `#{album}` - Current album 19 | * `#{track}` - Current track 20 | 21 | Here's the example in `.tmux.conf`: 22 | 23 | ```bash 24 | set -g status-right "♫ #{music_status} #{artist}: #{track} | %a %h-%d %H:%M " 25 | ``` 26 | 27 | Customize the icons with: 28 | 29 | ```bash 30 | set -g @spotify_playing_icon ">" 31 | set -g @spotify_paused_icon "=" 32 | 33 | # optional: defaults to `paused_icon` 34 | set -g @spotify_stopped_icon "X" 35 | ``` 36 | 37 | By default, Spotify is used as the media source. iTunes or Apple Music can be used by setting `MUSIC_APP` in your `bashrc`: 38 | 39 | ```bash 40 | # set tmux-spotify to use Apple Music instead of Spotify 41 | export MUSIC_APP="Music" 42 | ``` 43 | 44 | Set `MUSIC_APP` to `iTunes` instead on macOS Catalina. 45 | 46 | If the `status-right` overflows when the music title is too long, you can increase the `status-right-length` by using the following line in `.tmux.conf`: 47 | 48 | ```bash 49 | set -g status-right-length 70 50 | ``` 51 | 52 | ### Screenshots 53 | 54 | ![status](/screenshots/spotify-status.png) 55 | 56 | ### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended) 57 | 58 | Add the plugin to the list of TPM plugins in `.tmux.conf`: 59 | 60 | ```bash 61 | set -g @plugin 'robhurring/tmux-spotify' 62 | ``` 63 | 64 | Hit `prefix + I` to fetch the plugin and source it. 65 | 66 | ### Manual Installation 67 | 68 | Clone the repo: 69 | 70 | ```bash 71 | $ git clone https://github.com/robhurring/tmux-spotify ~/clone/path 72 | ``` 73 | 74 | Add this line to the bottom of `.tmux.conf`: 75 | 76 | ```bash 77 | run-shell ~/clone/path/music.tmux 78 | ``` 79 | 80 | Reload the TMUX environment: 81 | 82 | ```bash 83 | # type this in the terminal 84 | $ tmux source-file ~/.tmux.conf 85 | ``` 86 | 87 | -------------------------------------------------------------------------------- /music.tmux: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | source "$CURRENT_DIR/scripts/helpers.sh" 5 | 6 | artist="#($CURRENT_DIR/scripts/artist.sh)" 7 | album="#($CURRENT_DIR/scripts/album.sh)" 8 | track="#($CURRENT_DIR/scripts/track.sh)" 9 | music_status="#($CURRENT_DIR/scripts/status.sh)" 10 | 11 | artist_interpolation="\#{artist}" 12 | album_interpolation="\#{album}" 13 | track_interpolation="\#{track}" 14 | status_interpolation="\#{music_status}" 15 | 16 | #Backwards compatibility 17 | spotify_artist=artist 18 | spotify_album=album 19 | spotify_track=track 20 | spotify_status=music_status 21 | 22 | spotify_artist_interpolation=artist_interpolation 23 | spotify_album_interpolation=album_interpolation 24 | spotify_track_interpolation=track_interpolation 25 | spotify_status_interpolation=status_interpolation 26 | 27 | do_interpolation() { 28 | local output="$1" 29 | local output="${output/$artist_interpolation/$artist}" 30 | local output="${output/$album_interpolation/$album}" 31 | local output="${output/$track_interpolation/$track}" 32 | local output="${output/$status_interpolation/$music_status}" 33 | echo "$output" 34 | } 35 | 36 | update_tmux_uptime() { 37 | local option="$1" 38 | local option_value="$(get_tmux_option "$option")" 39 | local new_option_value="$(do_interpolation "$option_value")" 40 | set_tmux_option "$option" "$new_option_value" 41 | } 42 | 43 | main() { 44 | update_tmux_uptime "status-right" 45 | update_tmux_uptime "status-left" 46 | } 47 | main 48 | -------------------------------------------------------------------------------- /screenshots/spotify-status.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robhurring/tmux-spotify/6bc0b626a84aa913c3c96dd118ba4b3592f78bdb/screenshots/spotify-status.png -------------------------------------------------------------------------------- /scripts/album.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | source "$CURRENT_DIR/helpers.sh" 5 | 6 | print_album() { 7 | current_track_property "album" $APP 8 | } 9 | 10 | main() { 11 | print_album 12 | } 13 | 14 | main 15 | 16 | -------------------------------------------------------------------------------- /scripts/artist.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | source "$CURRENT_DIR/helpers.sh" 5 | 6 | print_artist() { 7 | current_track_property "artist" $APP 8 | } 9 | 10 | main() { 11 | print_artist 12 | } 13 | 14 | main 15 | -------------------------------------------------------------------------------- /scripts/helpers.sh: -------------------------------------------------------------------------------- 1 | APP=${MUSIC_APP:-"Spotify"} 2 | get_tmux_option() { 3 | local option=$1 4 | local default_value=$2 5 | local option_value=$(tmux show-option -gqv "$option") 6 | if [ -z "$option_value" ]; then 7 | echo "$default_value" 8 | else 9 | echo "$option_value" 10 | fi 11 | } 12 | 13 | set_tmux_option() { 14 | local option="$1" 15 | local value="$2" 16 | tmux set-option -gq "$option" "$value" 17 | } 18 | 19 | current_track_property() { 20 | local prop="${1}" 21 | read -r -d '' SCRIPT <