├── LICENSE ├── README.md ├── scripts ├── git_status.sh └── shared.sh └── simple_git_status.tmux /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Kristijan Husak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tmux simple git status 2 | 3 | Prints current pane git branch and uncommitted changes (if available). 4 | 5 | ![screenshot](https://i.imgur.com/SzOftNt.png) 6 | 7 | ## Installation 8 | ### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended) 9 | 10 | Add plugin to the list of TPM plugins in `.tmux.conf`: 11 | 12 | set -g @plugin 'kristijanhusak/tmux-simple-git-status' 13 | 14 | Add `#{simple_git_status}` to your `status-left` or `status-right` tmux option: 15 | 16 | ``` 17 | set -g status-left "#{simple_git_status}" 18 | ``` 19 | 20 | Hit `prefix + I` to fetch the plugin and source it. 21 | 22 | ### Manual Installation 23 | 24 | Clone the repo: 25 | 26 | $ git clone https://github.com/kristijanhusak/tmux-simple-git-status ~/clone/path 27 | 28 | Add this line to the bottom of `.tmux.conf`: 29 | 30 | run-shell ~/clone/path/simple_git_status.tmux 31 | 32 | Add `#{simple_git_status}` to your `status-left` or `status-right` tmux option: 33 | 34 | ``` 35 | set -g status-left "#{simple_git_status}" 36 | ``` 37 | 38 | Reload TMUX environment: 39 | 40 | $ tmux source-file ~/.tmux.conf 41 | 42 | ## FAQ 43 | 44 | *Q: Status is not updating in real time.* 45 | 46 | A: Frequency of update depends on tmux `status-interval` option. To refresh the status every 5 seconds, add `set -g status-interval 5` to your `.tmux.conf` 47 | 48 | *Q: There is a space before and after the status.* 49 | 50 | A: Those are added in order to allow easier styling and highlighting (like on screenshot). If you would add an empty space by yourself, you would get empty blocks in your statusline that doesn't hold anything. If you really want it to be removed, please file an issue. 51 | -------------------------------------------------------------------------------- /scripts/git_status.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | PANE_PATH=$(tmux display-message -p -F "#{pane_current_path}") 4 | cd $PANE_PATH 5 | 6 | git_changes() { 7 | local changes=$(git diff --shortstat | sed 's/^[^0-9]*\([0-9]*\)[^0-9]*\([0-9]*\)[^0-9]*\([0-9]*\)[^0-9]*/\1;\2;\3/') 8 | local changes_array=(${changes//;/ }) 9 | local untracked=$(git status --porcelain 2>/dev/null| grep -c "^??") 10 | local result=() 11 | 12 | if [[ $untracked != 0 ]]; then 13 | result+=("?$untracked") 14 | fi 15 | if [[ -n ${changes_array[0]} ]]; then 16 | result+=("~${changes_array[0]}") 17 | fi 18 | 19 | if [[ -n ${changes_array[1]} ]]; then 20 | result+=("+${changes_array[1]}") 21 | fi 22 | 23 | if [[ -n ${changes_array[2]} ]]; then 24 | result+=("-${changes_array[2]}") 25 | fi 26 | 27 | local joined=$(printf " %s" "${result[@]}") 28 | local joined=${joined:1} 29 | 30 | if [[ -n $joined ]]; then 31 | echo "$joined " 32 | fi 33 | } 34 | 35 | git_status() { 36 | local status=$(git rev-parse --abbrev-ref HEAD) 37 | local changes=$(git_changes) 38 | 39 | if [[ -n $status ]]; then 40 | printf " $status $changes" 41 | fi 42 | } 43 | 44 | main() { 45 | git_status 46 | } 47 | 48 | main 49 | -------------------------------------------------------------------------------- /scripts/shared.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | get_tmux_option() { 4 | local option=$1 5 | local default_value=$2 6 | local option_value=$(tmux show-option -gqv "$option") 7 | if [ -z "$option_value" ]; then 8 | echo "$default_value" 9 | else 10 | echo "$option_value" 11 | fi 12 | } 13 | 14 | set_tmux_option() { 15 | local option="$1" 16 | local value="$2" 17 | tmux set-option -gq "$option" "$value" 18 | } 19 | -------------------------------------------------------------------------------- /simple_git_status.tmux: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | 5 | git_status="#($CURRENT_DIR/scripts/git_status.sh)" 6 | placeholder="\#{simple_git_status}" 7 | 8 | source $CURRENT_DIR/scripts/shared.sh 9 | 10 | do_interpolation() { 11 | local string="$1" 12 | local interpolated="${string/$placeholder/$git_status}" 13 | echo "$interpolated" 14 | } 15 | 16 | update_tmux_option() { 17 | local option="$1" 18 | local option_value="$(get_tmux_option "$option")" 19 | local new_option_value="$(do_interpolation "$option_value")" 20 | set_tmux_option "$option" "$new_option_value" 21 | } 22 | 23 | main() { 24 | update_tmux_option "status-left" 25 | update_tmux_option "status-right" 26 | } 27 | 28 | main 29 | --------------------------------------------------------------------------------