Colours for PS2 and PS4.
[profile.git] / .profile.d / p4.bashrc
index 736d7e4..081e89b 100644 (file)
@@ -25,3 +25,30 @@ 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
+}