X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=rc%2Ffunctions;h=28135c712c0a05dc0806b36886fab4b69a9049a8;hb=56890e6a4f7bd3681fdc4b6db0cdce1ef0ec5e47;hp=18012885c8c281113734f72fba299e1a42b3768d;hpb=4f7c9ef6a17a313a1f430498d748f13d7682b045;p=clearscm.git diff --git a/rc/functions b/rc/functions index 1801288..28135c7 100644 --- a/rc/functions +++ b/rc/functions @@ -19,6 +19,11 @@ view_name= # Function to set the title bar. Works on the terminal emulators listed. function title_bar { + if [ $# -gt 1 ]; then + ROOT=shift + ROOT="${NORMAL}\($ROOT\)" + fi + prefix="$@" # Change $HOME -> ~ if [ "${PWD#$HOME*}" != "$PWD" ]; then @@ -39,8 +44,8 @@ function title_bar { fi # Add GIT info if available - if [ -d .git ]; then - current_dir="git: $(git branch | sed -n -e 's/^\* \(.*\)/\1/p') $current_dir" + if in_git_repo; then + current_dir="$current_dir [git: $(git branch | sed -n -e 's/^\* \(.*\)/\1/p')]" fi if [ "$TERM" = "hpterm" -o \ @@ -52,8 +57,12 @@ function title_bar { "$TERM" = "vt221" ]; then string=$(echo "${SYSNAME##*:}:$@") echo -n "${ESC}]2;$string\007" - elif [ "$TERM" = "cygwin" -o "$TERM" = "vt100" -o "$TERM" = "xterm" ]; then - PS1="\[\e]0;$prefix$current_dir\a\e[01;33m\]$SYSNAME:\[\e[0m\]" + elif [ "$TERM" = "cygwin" -o \ + "$TERM" = "vt100" -o \ + "$TERM" = "xterm" -o \ + "$TERM" = "xtermc" -o \ + "$TERM" = "xterm-256color" ]; then + PS1="\[\e]0;$prefix$current_dir\007\]$ROOT\[$B_YELLOW\]$SYSNAME:\[$B_WHITE\]" fi } # title_bar @@ -81,9 +90,9 @@ function title { # view and a string to indicate that you are root. function set_title { if [ $($id -u) -eq 0 ]; then - ROOT="Wizard " + root="Wizard " else - ROOT= + root= fi view_name=$(scm pwv -short 2> /dev/null); @@ -94,9 +103,9 @@ function set_title { if [[ $view_name = *NONE* ]]; then view_name="" - title_bar "$ROOT" + title_bar "$root" else - title_bar "${ROOT}View: $view_name: " + title_bar "${root}View: $view_name: " fi icon_name "${SYSNAME##*:}" @@ -105,25 +114,31 @@ function set_title { # Sets prompt on terminals listed. function set_prompt { if [ $($id -u) -eq 0 ]; then - if [ "$TERM" = "hpterm" -o \ - "$TERM" = "hp" -o \ - "$TERM" = "2392A" -o \ - "$TERM" = "dtterm" -o \ - ! -z "$DTTERM" ]; then - ROOT="${RED}Wizard$NORMAL " - elif [ "$TERM" = "vt100" -o \ - "$TERM" = "xterm" -o \ - "$TERM" = "vt220" ]; then - ROOT="${BOLD}${BLINK}Wizard$NORMAL " + if [ "$TERM" = "hpterm" -o \ + "$TERM" = "hp" -o \ + "$TERM" = "2392A" -o \ + "$TERM" = "dtterm" -o \ + "$TERM" = "vt100" -o \ + "$TERM" = "cygwin" -o \ + "$TERM" = "xterm" -o \ + "$TERM" = "xtermc" -o \ + "$TERM" = "xterm-256color" -o \ + "$TERM" = "vt220" ]; then + ROOT="\[${ROOT_COLOR}\]Wizard\[$NORMAL\] " + else + ROOT="Wizard " fi else ROOT="" fi - if [ "$TERM" = "vt100" -o \ - "$TERM" = "xterm" -o \ + if [ "$TERM" = "vt100" -o \ + "$TERM" = "cygwin" -o \ + "$TERM" = "xterm" -o \ + "$TERM" = "xtermc" -o \ + "$TERM" = "xterm-256color" -o \ "$TERM" = "vt220" ]; then - PS1="$ROOT$BOLD$SYSNAME:$NORMAL" + PS1="$ROOT\[$B_YELLOW\]$SYSNAME:\[$B_WHITE\]" else PS1="$ROOT$SYSNAME:" fi @@ -188,6 +203,18 @@ function ssh { set_prompt } # ssh +function processRunning { + if [ $ARCHITECTURE = "FreeBSD" ]; then + psopts="-aux" + else + psopts="-ef" + fi + + if [ $1 != '' ]; then + return $(ps $psopts | grep "$1" | grep -v "grep $1" | grep -v "grep -d skip" | wc -l) + fi +} # processRunning + function sj { if [ $ARCHITECTURE = "FreeBSD" ]; then psopts="-aux" @@ -199,7 +226,7 @@ function sj { ps $psopts | $PAGER else for str; do - ps $psopts | grep "$str" | grep -v "grep $str" | grep -v "grep -d skip" + ps $psopts | grep "$str" | grep -ve "grep $str" -e "grep -d skip" -e "grep --color=auto" done fi } # sj @@ -241,17 +268,47 @@ function cmdline { } # cmdline function user { + processRunning ypbind; ypbind=$? + processRunning winbind; winbind=$? + if [ $# -gt 0 ]; then - ypcat passwd | grep -i $@ + if [ $ypbind -gt 0 ]; then + ypcat passwd | grep -i $@ + elif [ $winbind -gt 0 ]; then + for user in $(wbinfo -u | grep -i $@); do + wbinfo --user-info $user + done + fi else - ypcat passwd | $PAGER + if [ $ypbind -gt 0 ]; then + ypcat passwd | $PAGER + elif [ $wbind -gt 0 ]; then + for user in $(wbinfo -u); do + wbinfo --user-info $user + done | $PAGER + fi fi } # user function group { + processRunning ypbind; ypbind=$? + processRunning winbind; winbind=$? + if [ $# -gt 0 ]; then - ypcat group | grep -i $@ + if [ $ypbind -gt 0 ]; then + ypcat group | grep -i $@ + elif [ $winbind -gt 0 ]; then + for group in $(wbinfo -g | grep -i $@); do + wbinfo --group-info $group + done + fi else - ypcat group | $PAGER + if [ $ypbind -gt 0 ]; then + ypcat group | $PAGER + elif [ $winbind -gt 0 ]; then + for group in $(wbinfo -g); do + wbinfo --group-info $group + done | $PAGER + fi fi } # group