What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Pretty prompt and "login" conveniences

smasher

Regular Contributor
Here's a pretty prompt with some nice "login" conveniences.



Here's the profile, in "/jffs/etc/profile":
Code:
## there's no .login support in this busybox shell
## so use this as a test to see if this is a fresh login
## otherwise, just skip this conditional list when this file is sourced
[ ${HISTFILE} ] || {
    ## alternative test, if $HISTFILE isn't working as expected: [ ${_} == ']' ]
    ## below here, within this curly-brace list, is what's done during a fresh login
    echo
    echo "curent time: $(date)"
    ## calculate and display boot time
    echo -n "boot time:   "
    date -d@$(( $( date +%s ) - $( cut -d. -f1 < /proc/uptime ) ))
    ## display uptime and load averages
    eval "echo uptime: $(date -ud@$( cut -d. -f1 < /proc/uptime ) +'$((%s/86400)) days %H:%M:%S')"
    echo -n "load avg: "
    cut -d ' ' -f1-3 < /proc/loadavg
    echo
    ## display filesystem stats for /tmp and /jffs
    df -h /tmp /jffs
    echo
    ## display used and available space in nvram
    echo -n "nvram " ; nvram show > /dev/random
    echo
}

## set up a nice prompt
## unfortunately this version of busybox chokes on multi-line prompts
export PS1="\[\e[35m\]\h\[\e[m\] \[\e[36m\]\w\[\e[m\]\[\e[97m\] \\$\[\e[m\] "
export PS2="\e[91m>\e[m "

## add custom scripts to the PATH
PATH=${PATH}:/jffs/bin

Then add this to "/jffs/scripts/init-start", to link (or copy) it into the $HOME directory at boot:
Code:
## set up fancy prompt stuff
/bin/ln  -s  /jffs/etc/profile  /root/.profile

If needed, copy it to "~/.profile".
Code:
ln -s /jffs/etc/profile ~/.profile

Tested and working spectacularly on an AC68U.

Updating the PATH is useful for scripts like these - https://www.snbforums.com/threads/cryptographic-hash-script.59988/

Here's how this pretty-prints the uptime - https://www.snbforums.com/threads/pretty-print-uptime.59986/

Here's how this pretty-prints the boot time - https://www.snbforums.com/threads/display-boot-time.59984/

Of course the prompt can be customised to your liking, but there are limitations in busybox, so a "normal" bash prompt may not work as expected.
 
Last edited:

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top