-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from PrashanthaTP/v4.0.0
Version 4.0.0 - Better folder structure - Custom Git Bash Prompts - **[Tmux](https://github.com/tmux/tmux)** config - minimalistic statusline - copy paste support - better user experience with tmux popups - **[Pandoc](https://pandoc.org/MANUAL.html)** - Scripts and templates for converting markdown files to Pdf - **[FZY](https://github.com/jhawthorn/fzy)** Fuzzy finder - use of FZY in dotfiles navigation (provided by tmux popup) - files/buffers navigation in Vim (git bash vim)
- Loading branch information
Showing
48 changed files
with
3,451 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,58 @@ | ||
############################################################################# | ||
# ┌────────────────────┐ | ||
# │ BASHRC │ | ||
# └────────────────────┘ | ||
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) | ||
#export TERM=xterm-256color | ||
VISUAL=nvim | ||
EDITOR=nvim | ||
export TERM=xterm-256color | ||
VISUAL=vim | ||
EDITOR=vim | ||
HISTSIZE=1000 | ||
HISTFILESIZE=2000 | ||
parse_git_branch() { | ||
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | ||
} | ||
# don't put duplicate lines or lines starting with space in the history. | ||
# See bash(1) for more options | ||
HISTCONTROL=ignoreboth | ||
############################################################################# | ||
# ┌─────────────────────────────┐ | ||
# │ ALIASES & FUNCTIONS │ | ||
# └─────────────────────────────┘ | ||
# must be sourced first | ||
############################################################################# | ||
source "$HOME/.config/bash/.bash_aliases" | ||
source "$HOME/.config/bash/.bash_functions" | ||
|
||
############################################################################# | ||
# ┌────────────────────┐ | ||
# │ ZSH │ | ||
# └────────────────────┘ | ||
# https://gist.github.com/fworks/af4c896c9de47d827d4caa6fd7154b6b | ||
############################################################################# | ||
# Launch Zsh | ||
#if [ -t 1 ]; then | ||
#exec zsh-5.8 | ||
#fi | ||
|
||
# export PS1="\u@\h \[\e[32m\]\w \[\e[91m\]\$(parse_git_branch)\[\e[00m\]$ " | ||
#export PS1="\[\033[35m\]\u@\[\033[32m\]\h \[\033[33m\]\w \[\033[91m\]\$(parse_git_branch)\[\033[00m\]$ " | ||
# PROMPT_COMMAND='echo -e "\e[?16;0;200c"' | ||
alias configfiles='git --git-dir="D:\dotfiles\dotfiles" --work-tree="$HOME"' | ||
################################################################################################################ | ||
# export PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \w\[\033[0;32m\]$(if git rev-parse --git-dir > /dev/null 2>&1; then echo " - ["; fi)$(git branch 2>/dev/null | grep "^*" )\[\033[0;32m\]$(if git rev-parse --git-dir > /dev/null 2>&1; then echo "]"; fi)\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] ' | ||
# export PS1="\[\e[0;32m\]\[\e[0m\]\[\e[0;32m\]\u\[\e[0;36m\] @ \[\033[0;36m\]\h \w\[\033[0;32m\] $(parse_git_branch)\n\[\033[0;32m\]└─\[\033[0m\]\[\033[0;32m\] \$\[\033[0m\]\[\033[0;32m\] ▶\[\033[0m\] " | ||
############################################################################# | ||
#https://gist.github.com/justintv/168835#gistcomment-2711710 | ||
############################################################################# | ||
# ┌────────────────────┐ | ||
# │ PROMPT │ | ||
# └────────────────────┘ | ||
# ref : https://gist.github.com/justintv/168835#gistcomment-2711710 | ||
############################################################################# | ||
#source_if_exists "$HOME/.config/git/minimal.sh" | ||
source_if_exists "$HOME/.config/git/git-prompt1.sh" | ||
#source_if_exists "$HOME/.config/git/minimal_fast_prompt.sh" | ||
#source_if_exists "$HOME/.config/git/powerlevel10k.sh" | ||
#source_if_exists "$HOME/.config/git/custom.sh" | ||
#source_if_exists "$HOME/.config/git/custom2.sh" | ||
|
||
#GIT_PS1_SHOWDIRTYSTATE=true | ||
#GIT_PS1_SHOWSTASHSTATE=true | ||
#GIT_PS1_SHOWUPSTREAM="auto" | ||
#PS1='\t:\[\033[32m\]$(__git_ps1 " (%s)")\[\033[00m\] \W$ ' | ||
############################################################################# | ||
# ┌────────────────────┐ | ||
# │ TMUX │ | ||
# └────────────────────┘ | ||
############################################################################# | ||
# Not so sure : putting it in seperate script makes detaching from tmux | ||
# session, results normal bash prompt | ||
source_if_exists "$HOME/.config/tmux/scripts/startup.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
alias configfiles='git --git-dir="D:\dotfiles\dotfiles" --work-tree="$HOME"' | ||
alias wikifiles='git --git-dir="D:\dotfiles\wiki\vimwiki\.git"\ | ||
--work-tree="D:\dotfiles\wiki\vimwiki"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
source_if_exists(){ | ||
[ -f "$1" ] && source "$1" | ||
} | ||
is_in_git_repo() { | ||
git rev-parse HEAD > /dev/null 2>&1 | ||
} | ||
gb() { | ||
is_in_git_repo && | ||
git branch -a -vv --color=always | grep -v '/HEAD\s' | | ||
fzy | sed 's/^..//' | awk '{print $1}' | | ||
sed 's#^remotes/[^/]*/##' | ||
} | ||
|
||
bind '"\er": redraw-current-line' | ||
bind '"\C-g\C-b": "$(gb)\e\C-e\er"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
git_stats() { | ||
local STATUS=$(git status -s 2> /dev/null) | ||
local ADDED=$(echo "$STATUS" | grep '??' | wc -l) | ||
local DELETED=$(echo "$STATUS" | grep ' D' | wc -l) | ||
local MODIFIED=$(echo "$STATUS" | grep ' M' | wc -l) | ||
local STATS='' | ||
if [ $ADDED != 0 ]; then | ||
STATS="\e[42m $ADDED " | ||
fi | ||
if [ $DELETED != 0 ]; then | ||
STATS="$STATS\e[101m $DELETED " | ||
fi | ||
if [ $MODIFIED != 0 ]; then | ||
STATS="$STATS\e[30;103m $MODIFIED " | ||
fi | ||
echo -e "\e[0m $STATS\e[0m" | ||
} | ||
__PS1_BEFORE='\n\n' | ||
__PS1_USER='\[\e[97;104m\] \u ' | ||
__PS1_LOCATION='\[\e[30;43m\] \w ' | ||
__PS1_GIT_BRANCH='\[\e[97;45m\] `__git_ps1` ' __PS1_GIT_STATS='`git_stats` ' | ||
__PS1_AFTER='\[\e[0m\]\n\n' | ||
|
||
export PS1="${__PS1_BEFORE}${__PS1_USER}${__PS1_LOCATION}${__PS1_GIT_BRANCH}${__PS1_GIT_STATS}${__PS1_AFTER}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# ANSI color escape sequences. Useful else, not just the prompt. | ||
C_Red='\e[2;31m'; C_BRed='\e[1;31m'; C_Green='\e[2;32m'; | ||
C_BGreen='\e[1;32m'; C_Yellow='\e[2;33m'; C_BYellow='\e[1;33m'; | ||
C_Grey='\e[2;37m'; C_Reset='\e[0m'; C_BPink='\e[1;35m'; | ||
C_Italic='\e[3m'; C_Blue='\e[2;34m'; C_BBlue='\e[1;34m'; | ||
C_Pink='\e[2;35m'; C_Cyan='\e[2;36m'; C_BCyan='\e[1;36m' | ||
|
||
# Values '1' or '2' are valid, for new and old versions, respectively. | ||
PROMPT_STYLE=2 | ||
|
||
PROMPT_PARSER(){ | ||
if [ $PROMPT_STYLE -eq 1 ]; then | ||
if git rev-parse --is-inside-work-tree &> /dev/null; then | ||
local Status=`git status -s` | ||
if [ -n "$Status" ]; then | ||
local StatusColor=$C_BRed | ||
else | ||
local StatusColor=$C_BGreen | ||
fi | ||
|
||
local Top=`git rev-parse --show-toplevel` | ||
read Line < "$Top"/.git/HEAD | ||
local Branch="$C_Italic$StatusColor${Line##*/}$C_Reset " | ||
fi | ||
|
||
if [ $1 -gt 0 ]; then | ||
local Exit="$C_BRed🗴$C_Reset" | ||
else | ||
local Exit="$C_BGreen🗸$C_Reset" | ||
fi | ||
|
||
local Basename=${PWD##*/} | ||
local Dirname=${PWD%/*} | ||
|
||
if [ "$Dirname/$Basename" == '/' ]; then | ||
CWD="$C_Italic$C_BGreen/$C_Reset" | ||
else | ||
CWD="$C_Grey$Dirname/$C_Italic$Basename$C_Reset" | ||
|
||
# If the CWD is too long, just show basename with '.../' prepended, if | ||
# it's valid to do so. I think ANSI escape sequences are being counted | ||
# in its length, causing it not work as it should, but I like the | ||
# result, none-the-less. | ||
local Slashes=${CWD//[!\/]/} | ||
TempColumns=$((COLUMNS + 20)) # <-- Seems to work around sequences. | ||
if ((${#CWD} > (TempColumns - ${#Branch}) - 2)); then | ||
if [ ${#Slashes} -ge 2 ]; then | ||
CWD="$C_Grey.../$C_Reset$C_BGreen$Basename$C_Reset" | ||
else | ||
CWD=$C_BGreen$Basename$C_Reset | ||
fi | ||
fi | ||
fi | ||
|
||
PS1="$Exit $Branch$CWD\n: " | ||
|
||
unset Line | ||
elif [ $PROMPT_STYLE -eq 2 ]; then | ||
X=$1 | ||
(( $X == 0 )) && X= | ||
|
||
if git rev-parse --is-inside-work-tree &> /dev/null; then | ||
GI=( | ||
'≎' # Clean | ||
'≍' # Uncommitted changes | ||
'≭' # Unstaged changes | ||
'≺' # New file(s) | ||
'⊀' # Removed file(s) | ||
'≔' # Initial commit | ||
'∾' # Branch is ahead | ||
'⮂' # Fix conflicts | ||
'!' # Unknown (ERROR) | ||
'-' # Removed file(s) | ||
) | ||
|
||
Status=`git status 2> /dev/null` | ||
Top=`git rev-parse --show-toplevel` | ||
|
||
local GitDir=`git rev-parse --git-dir` | ||
if [ "$GitDir" == '.' ] || [ "$GitDir" == "${PWD%%/.git/*}/.git" ]; then | ||
Desc="${C_BRed}∷ ${C_Grey}Looking under the hood..." | ||
else | ||
if [ -n "$Top" ]; then | ||
# Get the current branch name. | ||
IFS='/' read -a A < "$Top/.git/HEAD" | ||
local GB=${A[${#A[@]}-1]} | ||
fi | ||
|
||
# The following is in a very specific order of priority. | ||
if [ -z "$(git rev-parse --branches)" ]; then | ||
Desc="${C_BCyan}${GI[5]} ${C_Grey}Branch '${GB:-?}' awaits its initial commit." | ||
else | ||
while read -ra Line; do | ||
if [ "${Line[0]}${Line[1]}${Line[2]}" == '(fixconflictsand' ]; then | ||
Desc="${C_BCyan}${GI[7]} ${C_Grey}Branch '${GB:-?}' has conflict(s)." | ||
break | ||
elif [ "${Line[0]}${Line[1]}" == 'Untrackedfiles:' ]; then | ||
NFTTL=0 | ||
while read -a Line; do | ||
[ "${Line[0]}" == '??' ] && let NFTTL++ | ||
done <<< "$(git status --short)" | ||
printf -v NFTTL "%'d" $NFTTL | ||
|
||
Desc="${C_BCyan}${GI[3]} ${C_Grey}Branch '${GB:-?}' has $NFTTL new file(s)." | ||
break | ||
elif [ "${Line[0]}" == 'deleted:' ]; then | ||
Desc="${C_BCyan}${GI[9]} ${C_Grey}Branch '${GB:-?}' detects removed file(s)." | ||
break | ||
elif [ "${Line[0]}" == 'modified:' ]; then | ||
readarray Buffer <<< "$(git --no-pager diff --name-only)" | ||
printf -v ModifiedFiles "%'d" ${#Buffer[@]} | ||
Desc="${C_BCyan}${GI[2]} ${C_Grey}Branch '${GB:-?}' has $ModifiedFiles modified file(s)." | ||
break | ||
elif [ "${Line[0]}${Line[1]}${Line[2]}${Line[3]}" == 'Changestobecommitted:' ]; then | ||
Desc="${C_BCyan}${GI[1]} ${C_Grey}Branch '${GB:-?}' has changes to commit." | ||
break | ||
elif [ "${Line[0]}${Line[1]}${Line[3]}" == 'Yourbranchahead' ]; then | ||
printf -v TTLCommits "%'d" "${Line[7]}" | ||
Desc="${C_BCyan}${GI[6]} ${C_Grey}Branch '${GB:-?}' leads by $TTLCommits commit(s)." | ||
break | ||
elif [ "${Line[0]}${Line[1]}${Line[2]}" == 'nothingtocommit,' ]; then | ||
printf -v TTLCommits "%'d" "$(git rev-list --count HEAD)" | ||
|
||
Desc="${C_BCyan}${GI[0]} ${C_Grey}Branch '${GB:-?}' is $TTLCommits commit(s) clean." | ||
break | ||
fi | ||
done <<< "$Status" | ||
fi | ||
fi | ||
fi | ||
|
||
#PS1="\[${C_Reset}\]╭──╼${X}╾──☉ ${Desc}\[${C_Reset}\]\n╰─☉ " | ||
|
||
# 2021-06-13: Temporary block — just experimenting. | ||
if [ -n "$Desc" ]; then | ||
if [ -n "$X" ]; then | ||
PS1="\[${C_Reset}\]${Desc}\[${C_Reset}\]\n\[\e[91m\]${X} \[\e[0m\]\[\e[3;2;37m\]➙ \[\e[0m\] " | ||
else | ||
PS1="\[${C_Reset}\]${Desc}\[${C_Reset}\]\n\[\e[3;2;37m\]➙ \[\e[0m\] " | ||
fi | ||
else | ||
if [ -n "$X" ]; then | ||
PS1="\[${C_Reset}\]\[\e[91m\]${X} \[\e[0m\]\[\e[3;2;37m\]➙ \[\e[0m\] " | ||
else | ||
PS1="\[${C_Reset}\]\[\e[2;37m\]➙ \[\e[0m\] " | ||
fi | ||
fi | ||
|
||
unset Z Line Desc GI Status Top X GB CWD\ | ||
Buffer ModifiedFiles TTLCommits NFTTL | ||
fi | ||
} | ||
|
||
PROMPT_COMMAND='PROMPT_PARSER $?' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#! /bin/sh | ||
parse_git_branch() { | ||
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | ||
} | ||
|
||
#export PS1='\n\[\e[0;32m\]\[\e[0m\]\[\e[0;32m\]\u\[\e[0;36m\] @ \[\033[0;36m\]\h \w\[\033[0;32m\] $(parse_git_branch)'$'\n\[\033[0;32m\]└─\[\033[0m\]\[\033[0;32m\] \$\[\033[0m\]\[\033[0;32m\] ▶\[\033[0m\] ' | ||
#┌─╭─ | ||
|
||
#export PS1='\n\[\e[0;32m\]\[\e[0m\]\[\e[0;32m\]╭─ \u\[\e[0;36m\] @ \[\033[0;36m\]\h \w\[\033[0;32m\] $(parse_git_branch)'$'\n\[\033[0;32m\]╰─▶\[\033[0m\]\[\033[0;32m\] » $ \[\033[0m\]\[\033[0;32m\] \[\033[0m\] \[$(tput setaf 118)\]' | ||
# | ||
function __git_ps1_fast() { | ||
# ref : https://gist.github.com/urbanautomaton/5206496 | ||
local dir="$PWD" | ||
local git_dir | ||
|
||
until [[ -z "$dir" ]]; do | ||
git_dir="$dir/.git" | ||
if [[ -d "$git_dir" ]]; then | ||
echo " (`git rev-parse --abbrev-ref HEAD`)" | ||
return | ||
fi | ||
|
||
dir="${dir%/*}" | ||
done | ||
} | ||
export GIT_PS1_SHOWDIRTYSTATE= | ||
export GIT_PS1_SHOWUNTRACKEDFILES= | ||
export PS1='\n\[\e[0;36m\]╭─ \u @\h ::\w `__git_ps1_fast`'$'\n''\[\e[0;36m\]╰─▶$ \[\033[0m\]\[\e[0;32m\]' | ||
#export PS1='\u @\h\n╰─▶ » $ \[$(tput setaf 118)\]' |
Oops, something went wrong.