add git stuff to lf
This commit is contained in:
@@ -114,3 +114,71 @@ cmd mkbak %{{
|
||||
done
|
||||
|
||||
}}
|
||||
|
||||
# git stuff
|
||||
cmd git_branch ${{
|
||||
git branch | fzf | xargs git checkout
|
||||
pwd_shell="$(pwd | sed 's/\\/\\\\/g;s/"/\\"/g')"
|
||||
lf -remote "send $id updir; cd \"$pwd_shell\""
|
||||
}}
|
||||
map gb :git_branch
|
||||
map gp $clear; git pull --rebase || true; echo "press ENTER"; read ENTER
|
||||
map gs $clear; git status; echo "press ENTER"; read ENTER
|
||||
map gl $clear; git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
|
||||
|
||||
set info custom
|
||||
|
||||
cmd on-load &{{
|
||||
cd "$(dirname "$1")" || exit 1
|
||||
[ "$(git rev-parse --is-inside-git-dir 2>/dev/null)" = false ] || exit 0
|
||||
|
||||
cmds=""
|
||||
|
||||
for file in "$@"; do
|
||||
case "$file" in
|
||||
*/.git|*/.git/*) continue;;
|
||||
esac
|
||||
|
||||
status=$(git status --porcelain --ignored -- "$file" | cut -c1-2 | head -n1)
|
||||
|
||||
if [ -n "$status" ]; then
|
||||
cmds="${cmds}addcustominfo ${file} \"$status\"; "
|
||||
else
|
||||
cmds="${cmds}addcustominfo ${file} ''; "
|
||||
fi
|
||||
done
|
||||
|
||||
lf -remote "send $id :$cmds"
|
||||
}}
|
||||
|
||||
cmd on-cd &{{
|
||||
# display git repository status in your prompt
|
||||
source /usr/share/git/completion/git-prompt.sh
|
||||
GIT_PS1_SHOWDIRTYSTATE=auto
|
||||
GIT_PS1_SHOWSTASHSTATE=auto
|
||||
GIT_PS1_SHOWUNTRACKEDFILES=auto
|
||||
GIT_PS1_SHOWUPSTREAM=auto
|
||||
GIT_PS1_COMPRESSSPARSESTATE=auto
|
||||
git="$(__git_ps1 " [GIT BRANCH:> %s]")" || true
|
||||
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w\033[0m\033[33;1m$git\033[0m"
|
||||
lf -remote "send $id set promptfmt \"$fmt\""
|
||||
}}
|
||||
|
||||
cmd on-cd &{{
|
||||
# display repository status in your prompt
|
||||
if [ -d .git ] || [ -f .git ]; then
|
||||
branch="$(git branch --show-current 2>/dev/null)" || true
|
||||
remote="$(git config --get "branch.$branch.remote" 2>/dev/null)" || true
|
||||
url="$(git remote get-url "$remote" 2>/dev/null)" || true
|
||||
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w\033[0m\033[33;1m [GIT BRANCH:> $branch >> $url]\033[0m"
|
||||
elif [ -d .hg ]; then
|
||||
hg="$(hg branch 2>/dev/null)" || true
|
||||
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w\033[0m\033[33;1m [HG BRANCH:> $hg]\033[0m"
|
||||
elif [ -d .svn ]; then
|
||||
svn="$(svn info 2>/dev/null | awk '/^URL: /{print $2}')" || true
|
||||
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w\033[0m\033[33;1m [SVN URL:> $svn]\033[0m"
|
||||
else
|
||||
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"
|
||||
fi
|
||||
lf -remote "send $id set promptfmt \"$fmt\""
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user