View previous topic :: View next topic |
Author |
Message |
semiSfear Guru


Joined: 08 Jul 2003 Posts: 302 Location: Adelaide, SA
|
Posted: Mon Aug 18, 2003 12:16 am Post subject: mini, medi and maxi bash prompt magic |
|
|
I checked out this thread https://forums.gentoo.org/viewtopic.php?t=5850 and liked the extra informative bash prompt, but I wanted to change some things. So I ended up with this .bashrc, and I think some people might find it useful. So hopefully some will, enjoy
It is a .bashrc file with some handy aliases, but the highlight is 3 different bash prompts. One displaying minimal information, one standard bash prompt and a third prompt displaying all kinds of information. Each are loaded when typing either "minitty" or "meditty" or "maxitty". This is how they look:
minitty:
$: command
meditty:
[user@hostname:working_path]$ command
maxitty:
--[user@hostname]--[30 16 2 97Kb]---------------------------[/home/user]--
$: command
The "maxitty" got the most interesting functions. As you can see it displays the standard "user@hostname" info. It also displays the amount of directories in the current working directory, in this case 30. It also displays the amount of files, sym links and the total size of files in the current working directory.
Now I don't wan't to flame the author of this thread but there are some things I have to point out, as many of you may think this prompt is very similar to his. It's all about prefernces, no? Wront-i's prompt doesn't coun't hidden files and directories and don't coun't sym links seperately. His prompt also count the size of dirs. This one doesn't, my prefernce is to only know the total size of the files in the current directory. Another feature is that it counts the width of your terminal and fills it with "---" symbols. It also shortens the $PWD if it becomes too long so it don't break a new line in your terminal. Like so:
--[user@hostname]--[30 16 2 97Kb]----------------------[/home/user/path]--
$: command
--[user@hostname]--[30 16 2 97Kb]----------------[/home/user/path/path]--
$: command
--[user@hostname]--[30 16 2 97Kb]----------[/home/user/path/path/path]--
$: command
--[user@hostname]--[30 16 2 97Kb]--[...e/user/path/path/path/longpath]--
$: command
Ok, so enough of this boring description. Here comes the code:
Code: | #!/bin/bash
#----------------------------------------------------------------------
# MINI MEDI MAXI PROMPT
#----------------------------------------------------------------------
#
# $Revision: 1.0
# $Author: semiSfear
# $Source: /home/semisfear/.bashrc/
# $Description: A fancy bash prompt displaying various information
function prompt_command {
TERMWIDTH=${COLUMNS}
hostnam=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
usernam=$(whoami)
totdirs=$(/bin/ls -lA | /bin/grep ^d | wc -l | /bin/sed 's: ::g')
totfiles=$(/bin/ls -lA | /bin/grep ^- | wc -l | /bin/sed 's: ::g')
totlinks=$(/bin/ls -lA | /bin/grep ^l | wc -l | /bin/sed 's: ::g')
totsize=$(/bin/ls -lAh | /bin/grep -m 1 total | /bin/sed 's/total //')
newPWD="${PWD}"
let promptsize=$(echo -n "--[${usernam}@${hostnam}]--[${totdirs} ${totfiles} ${totlinks} ${totsize}b]--[${PWD}]--" \
| wc -c | tr -d " ")
let fillsize=${TERMWIDTH}-${promptsize}
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="${fill}-"
let fillsize=${fillsize}-1
done
if [ "$fillsize" -lt "0" ]
then
let cut=3-${fillsize}
newPWD="...$(echo -n $PWD | sed -e "s/\(^.\{$cut\}\)\(.*\)/\2/")"
fi
}
PROMPT_COMMAND=prompt_command
function minitty {
local NO_COLOR="\[\033[0m\]"
local GREEN="\[\033[01;32m\]"
local BLUE="\[\033[01;34m\]"
PS1="$GREEN\$$BLUE: $NO_COLOR"
}
function meditty {
local NO_COLOR="\[\033[0m\]"
local GREEN="\[\033[01;32m\]"
local BLUE="\[\033[01;34m\]"
local USERNAME="\u"
local HOSTNAME="\h"
local WORKDIR="\W"
PS1="$NO_COLOR[$GREEN$USERNAME$NO_COLOR@$GREEN$HOSTNAME$NO_COLOR:$BLUE$WORKDIR$NO_COLOR]$BLUE\$$NO_COLOR "
}
function maxitty {
local NO_COLOR="\[\033[0m\]"
local WHITE="\[\033[01;37m\]"
local GREEN="\[\033[01;32m\]"
local BLUE="\[\033[01;34m\]"
local CYAN="\[\033[01;36m\]"
local USERNAME="\u"
local HOSTNAME="\h"
local NEW_LINE="\n"
local NRFILES="\$(ls -lA | grep ^- | wc -l | /bin/sed 's: ::g')"
local NRDIRS="\$(ls -lA | grep ^d | wc -l | /bin/sed 's: ::g')"
local NRLINKS="\$(ls -lA | grep ^l | wc -l | /bin/sed 's: ::g')"
local TOTALSIZE="\$(/bin/ls -lAh | /bin/grep -m 1 total | /bin/sed 's/total //')"
local WORKDIR="\w"
PS1="$NO_COLOR--[$GREEN$USERNAME$NO_COLOR@$GREEN$HOSTNAME$NO_COLOR]--[$BLUE$NRDIRS $WHITE$NRFILES $CYAN$NRLINKS $WHITE$TOTALSIZE\[b\]$NO_COLOR]-\${fill}-[$BLUE\${newPWD}$NO_COLOR]--\
$NEW_LINE$GREEN\$$BLUE:$NO_COLOR "
}
# Set default fancy prompt (maxitty)
meditty
# Colors for ls, etc.
eval `dircolors -b /etc/DIR_COLORS`
alias d="ls --color"
alias ls="ls --color=auto"
alias ll="ls --color -l"
alias md="mkdir"
alias rd="rm -r"
alias cd..="cd .."
alias cd...="cd ../.."
alias cd....="cd ../../.."
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias untarz="tar -xvzf"
alias untarb="tar -xvjf"
alias ps="ps aux"
alias grep="grep --color=auto"
##uncomment the following to activate bash-completion:
[ -f /etc/profile.d/bash-completion ] && source /etc/profile.d/bash-completion
|
Hope some of you my find this bash prompt useful. If you got any comments or suggestions on improving the code please drop a line. _________________ DnB is my religion, Jungle is my church. |
|
Back to top |
|
 |
charlieg Advocate


Joined: 30 Jul 2002 Posts: 2149 Location: Manchester UK
|
Posted: Mon Aug 18, 2003 8:51 am Post subject: |
|
|
semiSfear wrote: | I am god... |
I can assure you, you are not God. Or even a God. _________________ Want Free games?
Free Gamer - open source games list & commentary
Open source web-enabled rich UI platform: Vexi |
|
Back to top |
|
 |
semiSfear Guru


Joined: 08 Jul 2003 Posts: 302 Location: Adelaide, SA
|
Posted: Mon Aug 18, 2003 10:36 am Post subject: |
|
|
charlieg wrote: | eat me, i'm tasty. |
I can assure you. You are not tasty. You look absolutely too salty for my taste. _________________ DnB is my religion, Jungle is my church. |
|
Back to top |
|
 |
cybe n00b


Joined: 22 Jul 2003 Posts: 67 Location: Finland
|
Posted: Mon Aug 18, 2003 11:05 am Post subject: |
|
|
nice one... added "if root then show different colors to remind cybe to be weewy weewy caweful while hunting wabbits with rm -rf in the root"....
And your sig isn't funny. God exists and He is not you (http://i.am/jah/bibcode.htm)
Code: |
#!/bin/bash
#----------------------------------------------------------------------
# MINI MEDI MAXI PROMPT
#----------------------------------------------------------------------
#
# $Revision: 1.0
# $Author: semiSfear
# $Source: /home/semisfear/.bashrc/
# $Description: A fancy bash prompt displaying various information
function prompt_command {
TERMWIDTH=${COLUMNS}
hostnam=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
usernam=$(whoami)
totdirs=$(/bin/ls -lA | /bin/grep ^d | wc -l | /bin/sed 's: ::g')
totfiles=$(/bin/ls -lA | /bin/grep ^- | wc -l | /bin/sed 's: ::g')
totlinks=$(/bin/ls -lA | /bin/grep ^l | wc -l | /bin/sed 's: ::g')
totsize=$(/bin/ls -lAh | /bin/grep -m 1 total | /bin/sed 's/total //')
newPWD="${PWD}"
let promptsize=$(echo -n "--[${usernam}@${hostnam}]--[${totdirs} ${totfiles} ${totlinks} ${totsize}b]--[${PWD}]--" \
| wc -c | tr -d " ")
let fillsize=${TERMWIDTH}-${promptsize}
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="${fill}-"
let fillsize=${fillsize}-1
done
if [ "$fillsize" -lt "0" ]
then
let cut=3-${fillsize}
newPWD="...$(echo -n $PWD | sed -e "s/\(^.\{$cut\}\)\(.*\)/\2/")"
fi
}
PROMPT_COMMAND=prompt_command
function minitty {
local NO_COLOR="\[\033[0m\]"
if [ `id -u` -gt 0 ]; then
local GREEN="\[\033[01;32m\]"
else
local GREEN="\[\033[01;31m\]"
fi
local BLUE="\[\033[01;34m\]"
PS1="$GREEN\$$BLUE: $NO_COLOR"
}
function meditty {
local NO_COLOR="\[\033[0m\]"
if [ `id -u` -gt 0 ]; then
local GREEN="\[\033[01;32m\]"
else
local GREEN="\[\033[01;31m\]"
fi
local BLUE="\[\033[01;34m\]"
local USERNAME="\u"
local HOSTNAME="\h"
local WORKDIR="\W"
PS1="$NO_COLOR[$GREEN$USERNAME$NO_COLOR@$GREEN$HOSTNAME$NO_COLOR:$BLUE$WORKDIR$NO_COLOR]$BLUE\$$NO_COLOR "
}
function maxitty {
local NO_COLOR="\[\033[0m\]"
local WHITE="\[\033[01;37m\]"
if [ `id -u` -gt 0 ]; then
local GREEN="\[\033[01;32m\]"
else
local GREEN="\[\033[01;31m\]"
fi
local BLUE="\[\033[01;34m\]"
local CYAN="\[\033[01;36m\]"
local USERNAME="\u"
local HOSTNAME="\h"
local NEW_LINE="\n"
local NRFILES="\$(ls -lA | grep ^- | wc -l | /bin/sed 's: ::g')"
local NRDIRS="\$(ls -lA | grep ^d | wc -l | /bin/sed 's: ::g')"
local NRLINKS="\$(ls -lA | grep ^l | wc -l | /bin/sed 's: ::g')"
local TOTALSIZE="\$(/bin/ls -lAh | /bin/grep -m 1 total | /bin/sed 's/total //')"
local WORKDIR="\w"
PS1="$NO_COLOR--[$GREEN$USERNAME$NO_COLOR@$GREEN$HOSTNAME$NO_COLOR]--[$BLUE$NRDIRS $WHITE$NRFILES $CYAN$NRLINKS $WHITE$TOTALSIZE\[b\]$NO_COLOR]-\${fill}-[$BLUE\${newPWD}$NO_COLOR]--\
$NEW_LINE$GREEN\$$BLUE:$NO_COLOR "
}
# Set default fancy prompt (maxitty)
meditty
# Colors for ls, etc.
| [/b] _________________ _________________________________
The MOST important book on the planet?
http://thewayhomeorfacethefire.info/ |
|
Back to top |
|
 |
semiSfear Guru


Joined: 08 Jul 2003 Posts: 302 Location: Adelaide, SA
|
Posted: Mon Aug 18, 2003 11:25 am Post subject: |
|
|
cybe wrote: | nice one... added "if root then show different colors to remind cybe to be weewy weewy caweful while hunting wabbits with rm -rf in the root"....
And your sig isn't funny. God exists and He is not you (http://i.am/jah/bibcode.htm)
|
Good point. I have set my root's .bashrc file to the same as above. Exceptions are a "#" symbol and red colored username
Sorry but I have to do this. Geeez what's up with this god thing. Aren't we all entitled to believe what we wan't? So if I would by any weird reason believe I am good that's up to me. It's just a stupid signature, not a statement or a threat to your believes. Just for the record, I'll change the stupid signature for the only reason so that this thread don't turn into a "is there a god" discussion. There, everyone is happy now. _________________ DnB is my religion, Jungle is my church. |
|
Back to top |
|
 |
bsolar Bodhisattva


Joined: 12 Jan 2003 Posts: 2764
|
Posted: Mon Aug 18, 2003 12:14 pm Post subject: |
|
|
From that site:
Quote: | It doesn't matter if we're looking in a text of 100 thousand or 100 million letters, you will not find coherent information - except in The Bible. |
Five lines above:
Quote: | Rips ExplAineD thaT eacH codE is a Case Of adDing Every fourth or twelfth or fiftieth letter to form a word.' The hidden message is READ THE CODE. |
Apparently 40 letters are enough...
BTW, please, there are other threads about religion and if you want to discuss a new topic post a new thread in OTW. _________________ I may not agree with what you say, but I'll defend to the death your right to say it. |
|
Back to top |
|
 |
pjp Administrator


Joined: 16 Apr 2002 Posts: 20589
|
Posted: Sun Sep 21, 2003 6:30 pm Post subject: Re: mini, medi and maxi bash prompt magic |
|
|
Followups to that thread. _________________ Quis separabit? Quo animo? |
|
Back to top |
|
 |
|