diff --git a/Makefile b/Makefile index 5e73c9f..4dd79e5 100644 --- a/Makefile +++ b/Makefile @@ -19,11 +19,12 @@ all: install: $(SOURCES) @echo 'Installing in ' $(PREFIX)/bin - cp git-radar $(PREFIX)/bin - cp radar-base.sh $(PREFIX)/bin - cp prompt.zsh $(PREFIX)/bin - cp prompt.bash $(PREFIX)/bin - cp fetch.sh $(PREFIX)/bin + cp git-radar $(PREFIX)/bin/ + cp radar-base.sh $(PREFIX)/bin/ + cp prompt.zsh $(PREFIX)/bin/ + cp prompt.bash $(PREFIX)/bin/ + cp prompt-tmux.bash $(PREFIX)/bin/ + cp fetch.sh $(PREFIX)/bin/ develop: $(SOURCES) @@ -32,4 +33,5 @@ develop: $(SOURCES) ln -s $(PWD)/radar-base.sh $(PREFIX)/bin/radar-base.sh ln -s $(PWD)/prompt.zsh $(PREFIX)/bin/prompt.zsh ln -s $(PWD)/prompt.bash $(PREFIX)/bin/prompt.bash + ln -s $(PWD)/prompt-tmux.bash $(PREFIX)/bin/prompt-tmux.bash ln -s $(PWD)/fetch.sh $(PREFIX)/bin/fetch.sh diff --git a/README.md b/README.md index 91f87cd..fc167e7 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,13 @@ function fish_prompt end ``` +**Tmux** + +Add to your `.tmux.conf` +``` +set -g status-left "#(git-radar --tmux)" +``` + ## Features ### Files status diff --git a/git-radar b/git-radar index f736e41..f08db16 100755 --- a/git-radar +++ b/git-radar @@ -57,12 +57,13 @@ if [[ -z $@ ]]; then echo "" echo "usage:" - echo " git-radar [--zsh|--bash|--fish] [--fetch]" + echo " git-radar [--zsh|--bash|--fish|--tmux] [--fetch]" echo "" echo " --fetch # Fetches your repo asynchronously in the background every 5 mins" echo " --zsh # Output prompt using Zsh style color characters" echo " --bash # Output prompt using Bash style color characters" echo " --fish # Output prompt using fish style color characters" + echo " --tmux # Output prompt using tmux style color codes" echo "" echo "Bash example:" echo " export PS1=\"\\W\\\$(git-radar --bash --fetch) \"" @@ -103,4 +104,8 @@ while [[ $# > 0 ]];do if [[ "$command" == "--bash" || "$command" == "--fish" ]]; then $dot/prompt.bash $args fi + + if [[ "$command" == "--tmux" ]]; then + $dot/prompt-tmux.bash $args + fi done diff --git a/prompt-tmux.bash b/prompt-tmux.bash new file mode 100755 index 0000000..b40ef6c --- /dev/null +++ b/prompt-tmux.bash @@ -0,0 +1,10 @@ +#! /usr/bin/env bash + +dot="$(cd "$(dirname "$0")"; pwd)" +args=$@ +source "$dot/radar-base.sh" + +if is_repo; then + prepare_tmux_colors + render_prompt +fi diff --git a/radar-base.sh b/radar-base.sh index 61503fd..f73a960 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -105,6 +105,45 @@ prepare_zsh_colors() { RESET_COLOR_STASH="%{${GIT_RADAR_COLOR_STASH:-$reset_color}%}" } +prepare_tmux_colors() { + if [ -f "$rcfile_path/.gitradarrc.zsh" ]; then + source "$rcfile_path/.gitradarrc.zsh" + elif [ -f "$rcfile_path/.gitradarrc" ]; then + source "$rcfile_path/.gitradarrc" + fi + + PRINT_F_OPTION="%s" + + COLOR_REMOTE_AHEAD="${GIT_RADAR_COLOR_REMOTE_AHEAD:-#[fg=green]}" + COLOR_REMOTE_BEHIND="${GIT_RADAR_COLOR_REMOTE_BEHIND:-#[fg=red]}" + COLOR_REMOTE_DIVERGED="${GIT_RADAR_COLOR_REMOTE_DIVERGED:-#[fg=yellow]}" + COLOR_REMOTE_NOT_UPSTREAM="${GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM:-#[fg=red]}" + + COLOR_LOCAL_AHEAD="${GIT_RADAR_COLOR_LOCAL_AHEAD:-#[fg=green]}" + COLOR_LOCAL_BEHIND="${GIT_RADAR_COLOR_LOCAL_BEHIND:-#[fg=red]}" + COLOR_LOCAL_DIVERGED="${GIT_RADAR_COLOR_LOCAL_DIVERGED:-#[fg=yellow]}" + + COLOR_CHANGES_STAGED="${GIT_RADAR_COLOR_CHANGES_STAGED:-#[fg=green]}" + COLOR_CHANGES_UNSTAGED="${GIT_RADAR_COLOR_CHANGES_UNSTAGED:-#[fg=red]}" + COLOR_CHANGES_CONFLICTED="${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-#[fg=yellow]}" + COLOR_CHANGES_UNTRACKED="${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-#[fg=white]}" + + COLOR_STASH="${GIT_RADAR_COLOR_STASH:-#[fg=yellow]}" + + local italic_m="$(printf '\xF0\x9D\x98\xAE')" + + COLOR_BRANCH="${GIT_RADAR_COLOR_BRANCH:-#[fg=default]}" + MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"#[fg=default]$italic_m#[fg=default]"}" + + PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" #[fg=black,bright]git:(#[fg=default]%{remote: }%{branch}%{ :local}#[fg=black,bright])#[fg=default]%{ :stash}%{ :changes}"}" + + RESET_COLOR_LOCAL="${GIT_RADAR_COLOR_LOCAL_RESET:-#[fg=default]}" + RESET_COLOR_REMOTE="${GIT_RADAR_COLOR_REMOTE_RESET:-#[fg=default]}" + RESET_COLOR_CHANGES="${GIT_RADAR_COLOR_CHANGES_RESET:-#[fg=default]}" + RESET_COLOR_BRANCH="${GIT_RADAR_COLOR_BRANCH_RESET:-#[fg=default]}" + RESET_COLOR_STASH="${GIT_RADAR_COLOR_STASH:-#[fg=default]}" +} + in_current_dir() { local wd="$(pwd)" if [[ "$wd" == $cwd ]]; then diff --git a/test-radar-base.sh b/test-radar-base.sh index 9f7f8ee..f9ca159 100755 --- a/test-radar-base.sh +++ b/test-radar-base.sh @@ -1,3 +1,5 @@ +#!/bin/sh + scriptDir="$(cd "$(dirname "$0")"; pwd)" source "$scriptDir/radar-base.sh" @@ -25,4 +27,4 @@ test_show_remote_status() { assertFalse $? } -. ./shunit/shunit2 \ No newline at end of file +. ./shunit/shunit2