During the brief interlude where I had Arch Linux installed, I discovered some distros apparently don’t have ‘tempfile’ command (looking on the web it would appear that Gentoo also lacks this useful command), which broke my config files archive scripts, so I created this bash script to do the job and set it up as an alias in my .bashrc:
# add our own tempfile command, if one doesn't already exist.
tempfile &> /dev/null
if [ $? -eq 127 ] # $? == 127 == command not found
then
if [ -e ~/configs/tempfile.sh ]
then
alias tempfile='bash ~/configs/tempfile.sh'
fi
fi
tempfile.sh:
#!/bin/bash
# tempfile.sh - temporary filename generator (for systems missing 'tempfile' command)
# Author: Laurence Hurst
# Date: 13 April 2006
filename=`mcookie`
filename=${filename::8}
dirname='/tmp'
while [ -a $dirname/$filename ]
do
echo "$dirname/$filename exists! Trying another filename." >&2
filename=`mcookie`
filename=${filename::8}
done
echo "$dirname/$filename"
However the scripts don’t read .bashrc (where this is setup as an alias), and so it doesn’t work. There must be a way to make the scripts use aliases setup in .bashrc, I just can’t figure out how.
.:Update to the Update:.
Accoding to some information I found on interactive vs non-interactive shells it is not possible to use personal aliases in bash scripts for the reason that if you give the script to someone else they probably won’t have the same aliases so it won’t work, which make sense most of the time but not here where the script is only for me, and the alias is for systems which lack a tempfile utility.
I also found this sample .bashrc, which creates a prompt with the current load average which might be nify to add to my (rapidly growing) bash prompt:
152 function powerprompt()
153 {
154 _powerprompt()
155 {
156 LOAD=$(uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g" )
157 }
158
159 PROMPT_COMMAND=_powerprompt
160 case $TERM in
161 *term | rxvt )
162 PS1="${HILIT}[\A \$LOAD]$NC\n[\h \#] \W > \[33]0;\${TERM} [\u@\h] \w07\]" ;;
163 linux )
164 PS1="${HILIT}[\A - \$LOAD]$NC\n[\h \#] \w > " ;;
165 * )
166 PS1="[\A - \$LOAD]\n[\h \#] \w > " ;;
167 esac
168 }
169
170 powerprompt # this is the default prompt - might be slow
I did, however remember that ~/bin, if it exists, is added to the path in my .bashrc so a symlink ~/bin/tempfile -> ~/configs/tempfile.sh (I renamed the scripts directory in my previous post to configs) should work – I will have to try it tomorrow, for now though bed
.