loading...

re: 10 simple Linux tips which save 50% of my time in the command line VIEW POST

FULL DISCUSSION
 

I keep a script that can run (with very minor changes, if any) across several of the "sh" based shells, including the original AT&T sh, ksh, zsh, and bash, though the newer shells now incorporate quite a bit of the functionality, so I've used them less frequently recently:

directory stack functions

declare -i DNUM=0
DLIST[DNUM]=pwd

function g # go to a directory
{
if builtin cd "$@" >/dev/null && [ ${DLIST[DNUM]} != "$PWD" ]
then
DNUM=DNUM+1
DLIST[DNUM]=$PWD
fi

if DISPLAY exists, then set titlebar and icon.

if [ -n "$DISPLAY" ]; then
    titlebar="$USER @ $HOST : $PWD"
fi
pwd

}

function gb # go back
{
if (( $DNUM > 0 ))
then
DNUM=DNUM-1
fi
g ${DLIST[DNUM]}
}

function gn # go to selected (nth) dir
{
select DIR in echo ${DLIST[*]} | tr " " "\012" | sort -u -y0
do
if [ "$DIR" ]
then
g $DIR
else
g $REPLY
fi
break
done
}

function up # go up n levels
{
declare -i levels

levels=${1}

if [ -z "${1}" ] && [ ${PWD} != "/" ]
then
  g ..
  return $?
fi

while [ ${levels} -gt 0 ] && [ ${PWD} != "/" ]
do
  g ..
  levels=levels-1
done

}

function addpath
{
PATH=$PATH:$1
echo $PATH
}

function todo
{
echo date '+%D %H:%M' >> ~/todo
echo "$*" >> ~/todo
echo >> ~/todo
}

Main # <--- Main

Set the default directory and file protection mask. By default, do

not mask any protection on my ownership, but remove default write

access for the group, and do not give "world" any default access.

(I add or subtract various things, adding functions or procedures

that I am frequently using, and remove them when inappropriate

at a particular assignment. Sometimes I can send portions of a

script by Email; other times sending anything in is frowned upon

so I have to create bits and pieces of my personal tools manually).

export SHELL=~/bin/bash # usually my default shell
umask 022

OS=$(uname)
myterm=$(who am i)
myterm=$(echo $myterm | awk -F" " '{ print $2 }')
echo "The current HOST is $HOST"
echo "The current terminal is $myterm"
echo "The current shell is $SHELL"

return # get out of any functions I may be in

Finished .bashrc

Code of Conduct Report abuse