From b11849fbbd75d6e3a3091a59e132f5e08c574392 Mon Sep 17 00:00:00 2001 From: Diogo Alexsander Cavilha Date: Sun, 1 Dec 2019 12:42:45 -0300 Subject: [PATCH] :sparkles: Add new styles - Add human-single-line style. - Add human-dark-single-line style. closes #45 --- CHANGELOG.md | 5 ++ commands.sh | 2 + fancygit-completion | 2 + prompt_styles/human-dark-single-line.sh | 101 ++++++++++++++++++++++++ prompt_styles/human-single-line.sh | 98 +++++++++++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 prompt_styles/human-dark-single-line.sh create mode 100644 prompt_styles/human-single-line.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a16d49..20b1cb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Fancy Git Changelog +### v6.2.6 + +- Add `human-single-line` style. +- Add `human-dark-single-line` style. + ### v6.1.6 - Improve the way fancygit looks for its configurations. diff --git a/commands.sh b/commands.sh index 1958ced..956ee1d 100755 --- a/commands.sh +++ b/commands.sh @@ -191,7 +191,9 @@ case "$1" in "double-line") fg_update_app_config "style" "fancy-double-line";; "simple-double-line") fg_update_app_config "style" "simple-double-line";; "human") fg_update_app_config "style" "human";; + "human-single-line") fg_update_app_config "style" "human-single-line";; "human-dark") fg_update_app_config "style" "human-dark";; + "human-dark-single-line") fg_update_app_config "style" "human-dark-single-line";; "dark") fg_update_app_config "style" "dark";; "dark-double-line") fg_update_app_config "style" "dark-double-line";; "light") fg_update_app_config "style" "light";; diff --git a/fancygit-completion b/fancygit-completion index b402abe..789d1cc 100644 --- a/fancygit-completion +++ b/fancygit-completion @@ -10,7 +10,9 @@ _fancygit() { update \ configure-fonts \ human \ + human-single-line \ human-dark \ + human-dark-single-line \ default \ double-line \ simple \ diff --git a/prompt_styles/human-dark-single-line.sh b/prompt_styles/human-dark-single-line.sh new file mode 100644 index 0000000..d493a49 --- /dev/null +++ b/prompt_styles/human-dark-single-line.sh @@ -0,0 +1,101 @@ +#!/bin/bash +# +# Author: Diogo Alexsander Cavilha +# Date: 06.11.2018 + +. ~/.fancy-git/aliases +. ~/.fancy-git/fancygit-completion +. ~/.fancy-git/commands.sh + +fg_branch_status() { + . ~/.fancy-git/config.sh + + local info="" + + if [ "$git_has_unpushed_commits" ] + then + info="${info}${light_green}${git_number_unpushed_commits}^${none} " + fi + + if [ "$git_number_untracked_files" -gt 0 ] + then + info="${info}${cyan}?${none} " + fi + + if [ "$git_number_changed_files" -gt 0 ] + then + info="${info}${light_green}+${none}${light_red}-${none} " + fi + + if [ "$git_stash" != "" ] + then + info="${info}∿${none} " + fi + + if [ "$staged_files" != "" ] + then + info="${info}${light_green}✔${none} " + fi + + if [ "$info" != "" ]; then + info=$(echo "$info" | sed -e 's/[[:space:]]*$//') + echo " [$info]" + return + fi + + echo "" +} + +fg_branch_name() { + local branch_name=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) + local only_local_branch=$(git branch -a 2> /dev/null | egrep "remotes/origin/${branch_name}" | wc -l) + local orange="\\033[95;38;5;214m" + local light_green="\\[\\e[92m\\]" + local red="\\[\\e[31m\\]" + local none="\\[\\e[39m\\]" + local on="${red}on${none}" + + if [ "$branch_name" != "" ] && [ "$only_local_branch" -eq 0 ]; then + branch_name="${orange}$branch_name${none}${light_green}*${none}" + fi + + if [ "$branch_name" != "" ]; then + branch_name=" ${on} ${orange}$branch_name${none}" + fi + + echo "$branch_name$(fg_branch_status) " +} + +fancygit_prompt_builder() { + . ~/.fancy-git/update_checker.sh && _fancygit_update_checker + + # Colors + local bold="\\[\\e[1m\\]" + local bold_none="\\[\\e[0m\\]" + local none="\\[\\e[39m\\]" + local red="\\[\\e[31m\\]" + + local at="${red}at${none}" + local in="${red}in${none}" + local on="${red}on${none}" + local venvfor="${red}for${none}" + + # Prompt + local user="\u" + local host="\h" + local where="\W" + local venv="" + + if fg_show_full_path + then + where="\w" + fi + + if ! [ -z ${VIRTUAL_ENV} ]; then + venv="`basename \"$VIRTUAL_ENV\"` ${venvfor} " + fi + + PS1="${bold}${venv}${user} ${at} ${host} ${in} $where$(fg_branch_name)${bold_none}\$ " +} + +PROMPT_COMMAND="fancygit_prompt_builder" diff --git a/prompt_styles/human-single-line.sh b/prompt_styles/human-single-line.sh new file mode 100644 index 0000000..69e445d --- /dev/null +++ b/prompt_styles/human-single-line.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# +# Author: Diogo Alexsander Cavilha +# Date: 06.11.2018 + +. ~/.fancy-git/aliases +. ~/.fancy-git/fancygit-completion +. ~/.fancy-git/commands.sh + +fg_branch_status() { + . ~/.fancy-git/config.sh + + local info="" + + if [ "$git_has_unpushed_commits" ] + then + info="${info}${light_green}${git_number_unpushed_commits}^${none} " + fi + + if [ "$git_number_untracked_files" -gt 0 ] + then + info="${info}${cyan}?${none} " + fi + + if [ "$git_number_changed_files" -gt 0 ] + then + info="${info}${light_green}+${none}${light_red}-${none} " + fi + + if [ "$git_stash" != "" ] + then + info="${info}∿${none} " + fi + + if [ "$staged_files" != "" ] + then + info="${info}${light_green}>${none} " + fi + + if [ "$info" != "" ]; then + info=$(echo "$info" | sed -e 's/[[:space:]]*$//') + echo " [$info]" + return + fi + + echo "" +} + +fg_branch_name() { + local light_magenta="\\[\\e[95m\\]" + local branch_name=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) + local only_local_branch=$(git branch -a 2> /dev/null | egrep "remotes/origin/${branch_name}" | wc -l) + local light_green="\\[\\e[92m\\]" + local none="\\[\\e[39m\\]" + + if [ "$branch_name" != "" ] && [ "$only_local_branch" -eq 0 ]; then + branch_name="${light_magenta}$branch_name${none}${light_green}*${none}" + fi + + if [ "$branch_name" != "" ]; then + branch_name=" on ${light_magenta}$branch_name${none}" + fi + + echo "$branch_name$(fg_branch_status) " +} + +fancygit_prompt_builder() { + . ~/.fancy-git/update_checker.sh && _fancygit_update_checker + + # Colors + local blue="\\[\\e[34m\\]" + local bold="\\[\\e[1m\\]" + local bold_none="\\[\\e[0m\\]" + local light_green="\\[\\e[92m\\]" + local light_yellow="\\[\\e[93m\\]" + local none="\\[\\e[39m\\]" + local orange="\\033[95;38;5;214m" + + # Prompt + local user="${orange}\u${none}" + local host="${light_yellow}\h${none}" + local where="${light_green}\w${none}" + local venv="" + + if ! fg_show_full_path + then + where="${light_green}\W${none}" + fi + + if ! [ -z ${VIRTUAL_ENV} ]; then + venv="${light_yellow}`basename \"$VIRTUAL_ENV\"`${none} for " + fi + + PS1="${bold}${venv}${user} at ${host} in $where$(fg_branch_name)${bold_none}\$ " +} + +PROMPT_COMMAND="fancygit_prompt_builder" +