X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=.profile.d%2Fp4.bashrc;h=081e89b549162f043e6dd09819cac4baf4b96a2e;hp=93627f1149afb56110f691da08414da7ae4b2e07;hb=0a1657631dbee738cce2a9bbe7ec8405a67bea42;hpb=76559e10296433ab488b9d9940c50a39282ee49a diff --git a/.profile.d/p4.bashrc b/.profile.d/p4.bashrc index 93627f1..081e89b 100644 --- a/.profile.d/p4.bashrc +++ b/.profile.d/p4.bashrc @@ -1,3 +1,4 @@ +# profile-required: vim.bashrc if [ ! -z "$SUDO_USER" ]; then export P4USER=$SUDO_USER export P4TICKETS=/tmp/.p4tickets.$SUDO_USER @@ -5,14 +6,49 @@ else export P4USER=$USER fi export P4CONFIG=.p4config -export P4DIFF="diff -u" -if [ -e "$HOME/.vim/script/p4" ]; then - export P4EDITOR="vim -S '$HOME/.vim/script/p4'" -else - export P4EDITOR=vim -fi +eval $(alias diff 2>/dev/null | sed 's/^alias diff/P4DIFF/') +export P4DIFF="${P4DIFF:-diff} -u" +eval $(alias vim 2>/dev/null | sed 's/^alias vim/p4vim/') +p4vim=${p4vim:-vim} +P4EDITOR="$p4vim" +p4script=$(find_target_profile ".vim/script/p4") +[ -n "$p4script" ] && P4EDITOR="$p4vim -S '$p4script'" +export P4EDITOR if [ -z "$DISPLAY" ]; then - export P4MERGE="vim -o -c '3wincmd j' -c 'wincmd L'" + p4script=$(find_target_profile ".vim/script/merge") + if [ -n "$p4script" ]; then + export P4MERGE="$p4vim -S '$p4script'" + else + export P4MERGE="$p4vim -o -c '3wincmd j' -c 'wincmd L'" + fi else export P4MERGE="p4merge" fi +unset p4script p4vim + +# p4: Wrapper around p4 to add some other features. +function p4() { + if [ -z "$P4OPTSTRING" -a ! "${P4OPTSTRING+xxx}" = "xxx" ]; then + local p4=$(which p4) + P4OPTSTRING="$(strings $p4 | grep H:)" + fi + + local opts= + OPTIND=1 + if [ -n "$P4OPTSTRING" ]; then + while getopts "$P4OPTSTRING" opt; do + [ "$opt" = "?" ] && continue + opts="$opts -$opt $OPTARG" + done + shift $((OPTIND-1)) + fi + + command="$1"; shift + custom=${PROFILE_HOME:-~}/opt/p4/p4-"$command" + + if [ -x "$custom" ]; then + "$custom" $opts "$command" ${1+"$@"} + else + ( exec p4 $opts "$command" ${1+"$@"} ) + fi +}