From 22e56e08ed2c1b9685b711e160c35f4679eec4f9 Mon Sep 17 00:00:00 2001 From: adefaria Date: Thu, 2 Oct 2014 12:58:36 -0700 Subject: [PATCH] Added code to allow one to use my startup scripts by doing source ~adefaria/.rc/bash_login. Fixed bug so that when I am root the word Wizard appears in the prompt. --- rc/bash_login | 19 +++++++++++++++++++ rc/functions | 10 ++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/rc/bash_login b/rc/bash_login index 79d1c60..88d27e0 100644 --- a/rc/bash_login +++ b/rc/bash_login @@ -11,6 +11,22 @@ # (c) Copyright 2000-2005, Andrew@DeFaria.com, all rights reserved. # ################################################################################ +# The following will set HOME, temporarily, to the directory of my $HOME so that +# somebody other than me can envoke my startup scripts. I use this mainly for +# when I become root with sudo -s and what a better environment that the bare +# bones root environment gives you. Note that for us to be effective one must +# source (or .) this file and if so the ${BASH_ARGV[0]} is the normal $0 +home=$(dirname ${BASH_ARGV[0]}) + +# Strip off .rc +home=${home/%\/\.rc/} + +# Now set $HOME if $home is different. +saved_home=$HOME +if [ "$HOME" != "$home" ]; then + HOME=$home +fi + # Set ARCHITECTURE of the machine KERNEL=$(uname -s) if [[ $KERNEL = CYGWIN* ]]; then @@ -260,6 +276,9 @@ done # Set display to local export DISPLAY=${DISPLAY:-:0} +# Reset home in case it changed +HOME=$saved_home + # Now go home (in case we were not autmatically cd'ed there) if [ $(id -u) -ne 0 ]; then cd diff --git a/rc/functions b/rc/functions index 69f8aa1..458a69b 100644 --- a/rc/functions +++ b/rc/functions @@ -19,7 +19,13 @@ 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 current_dir="~${PWD#$HOME*}" @@ -53,7 +59,7 @@ function title_bar { 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\]" + PS1="\[\e]0;$prefix$current_dir\a$ROOT\e[01;33m\]$SYSNAME:\[\e[0m\]" fi } # title_bar @@ -96,7 +102,7 @@ function set_title { view_name="" title_bar "$ROOT" else - title_bar "${ROOT}View: $view_name: " + title_bar "$ROOT" "View: $view_name: " fi icon_name "${SYSNAME##*:}" -- 2.17.1