Results 1 to 3 of 3

Thread: [HowTo] bash completion to your needs

  1. #1
    Join Date
    Jul 2007
    Location
    Austria
    Posts
    1,336

    [HowTo] bash completion to your needs

    Many of us are using bash, because bash has usually more possibilities as the regular shell, but just a few have knowledge about the bash extensions.

    Pre-condition is an install according Wengis howto.
    ATTENTION: store your old /opt/etc/profile !

    After installing bash with
    Code:
    ipkg install bash
    and restore your old profile again to /opt/etc/profile, you can extend and adjust your bash to your needs.
    For instance: An output to STDOUT with different colors is very easy. Even complete backups can be done with one command.
    Of course, any kind of the usual alias is available as well as completions of existing commands.
    Instancing completions of existing commands, you'll find as example the regular exit command.

    Any kind of extensions or changes for your bash are stored in the file .bashrc in your home directory

    Home directory for admin/root is /tmp/local/root

    Code:
    touch .bashrc
    and add to the new .bashrc file

    Code:
    #bashrc file, collection of useful bash extensions
    #Newbiefans bash, mostly overtaken from different sources
    #feel free to copy and modify
    #a good place to get more is http://bashscripts.org
    
    # EXPORTS
    
    #export PS1="[\[\033[1;34m\w\[\033[0m]\n[\t \u]$ "
    #export HISTFILESIZE=3000 # the bash history should save 3000 commands
    export HISTCONTROL=ignoredups #don't put duplicate lines in the history.
    #export PATH
    
    # Define a few Color's
    BLACK='\e[0;30m'
    BLUE='\e[0;34m'
    GREEN='\e[0;32m'
    CYAN='\e[0;36m'
    RED='\e[0;31m'
    PURPLE='\e[0;35m'
    BROWN='\e[0;33m'
    LIGHTGRAY='\e[0;37m'
    DARKGRAY='\e[1;30m'
    LIGHTBLUE='\e[1;34m'
    LIGHTGREEN='\e[1;32m'
    LIGHTCYAN='\e[1;36m'
    LIGHTRED='\e[1;31m'
    LIGHTPURPLE='\e[1;35m'
    YELLOW='\e[1;33m'
    WHITE='\e[1;37m'
    NC='\e[0m'              # No Color
    # Sample Command using color: echo -e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}${CYAN} - DISPLAY on ${RED}$DISPLAY${NC}\n"
    
    # Source global definitions
    if [ -f /etc/bashrc ]; then
       . /opt/etc/bashrc
    fi
    
    # enable programmable completion features
    if [ -f /etc/bash_completion ]; then
       . /opt/etc/bash_completion
    fi
    
    # ALIAS
    #alias playw='for i in *.wav; do play $i; done'
    #alias playo='for i in *.ogg; do play $i; done'
    #alias playm='for i in *.mp3; do play $i; done'
    #alias backup='dd if=/dev/discs/disc0/part$1 of=/dev/discs/disc1/part$2' #Copy Partition: backup 2 1 (copy part2 to part1)
    alias home='cd /tmp/local/root'
    alias pg='ps aux | grep'  #requires an argument
    alias un='tar -zxvf'
    alias mti='df -hT' #mounted_info
    alias ping1='ping -c 1'
    alias pingx='ping -c $1'  #parameter needed, how often to ping syntax: pingx 3 192.168.x.x
    alias openports='netstat -nape --inet'
    alias ns='netstat -alnp --protocol=inet | grep -v CLOSE_WAIT | cut -c-6,21-94 | tail +2'
    alias du='du -h --max-depth=1'
    alias da='date "+%Y-%m-%d %A    %T %Z"'
    alias la='ls -Al'               # show hidden files
    alias lx='ls -lXB'              # sort by extension
    alias lk='ls -lSr'              # sort by size
    alias lc='ls -lcr'      # sort by change time  
    alias lu='ls -lur'      # sort by access time   
    alias lr='ls -lR'               # recursive ls
    alias lt='ls -ltr'              # sort by date
    alias lm='ls -al |more'         # pipe through 'more'
    alias ls='ls --color=auto -la'
    alias ps='ps axf'
    alias pss='ps axf | grep'
    alias df='df -h'
    alias mc='mc -c'
    alias ipt='iptables -nv -L'
    alias wi='whereis'
    alias n='nano'
    export TERMINFO=/opt/share/terminfo
    
    # FUNCTIONS
    backup ()
    {
      ok1=false
      ok2=false
      if [ -z $1 ] ; then
         echo "No source partition determined"
       else
         ok1=true
      fi
      if [ -z $2 ] ; then
         echo "No target partition determined"
       else
         ok2=true
      fi   
      if [ $ok1 = true ] && [ $ok2 = true ] ; then 
         #check it before!!
         #dd if=/dev/discs/disc0/part$1 of=/dev/discs/disc1/part$2
         echo -e "${GREEN}backup from $1 to $2${NC}"
         ok1=false ; ok2=false
       else
         echo "Syntax; 'backup 2 1' where 2 is partition 2 of the first disc resp. /opt on an asus router"
         echo "and 1 is the target partition of the next disc!"
         echo "Read at http://wl500g.info Thread 'ultimative bash'"
      fi
    }
    
    netinfo ()
    {
      echo "--------------- Network Information ---------------"
      /sbin/ifconfig | awk /'inet addr/ {print $2}'
      /sbin/ifconfig | awk /'Bcast/ {print $3}'
      /sbin/ifconfig | awk /'inet addr/ {print $4}'
    
      #/sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
      echo "---------------------------------------------------"
    }
    
    spin ()
    {
      echo -ne "${RED}-"
      echo -ne "${GREEN}\b|"    
      echo -ne "${BLUE}\bx"
      sleep .02
      echo -ne "${RED}\b+${NC}"
    }
    
    function _exit() #run upon exit of bash
    {
      echo -e "${RED}Leaving bash - See you soon honey, take care${NC}"
    }
    trap _exit EXIT
    
    #start screen
    clear
    for i in `seq 1 15` ; do spin; done
    echo -ne "${GREEN} Bash on Asus-Routers ${NC}" 
    for i in `seq 1 15` ; do spin; done ; echo
    echo -e "Kernel Information: " `uname -a`
    echo -e ${LIGHTBLUE}`bash --version`
    echo -ne "Hello $USER today is "; date
    echo -e "${GREEN}"; cal
    echo -ne "${CYAN}"; netinfo
    echo -ne "${LIGHTBLUE}Uptime for this router at"; uptime
    for i in `seq 1 15` ; do spin; done
    echo -ne "${GREEN} http://wl500g.info ${NC}"
    for i in `seq 1 15` ; do spin; done
    echo
    Start your bash with: bash
    Leave the bash with: exit
    To control which shell is running: echo $0

    Save everything to your flash with the usual:
    Code:
    flashfs save
    flashfs commit
    flashfs enable
    reboot
    Everybody can extend the bash to his needs.
    I would appreciate it when somebody would post some useful extensions

    Have a closer look to the file .bashrc in order to find the new commands.
    If you have any problem, just ask.

    Suggestions and completions, error reports and corrections are always greatly appreciated!

    have fun
    newbiefan
    Alle HowTo's, all howto's

    RT-N16 1.9.2.7-rtn-r3121, Samba, VSFTP, Lightthpd, PHP, Perl, MySQL, Serendipity, Aria2web, HDD 640GB
    RT-N66U, 16GB MicroSD/ 2 Partitions, 2,5" HDD 1TB, running with Merlin's FW and Entware, 16 Mbit A1,
    Netgear DGND 3700V2, QNAP TS119PII 4 TB, QNAP TS209 2 TB Raid1, Backup Synology DS107+ 1 TB, HP CP1515n

  2. #2
    Join Date
    Dec 2007
    Location
    The Netherlands - Eindhoven
    Posts
    1,767
    looks good newbie fan

    this line pops up tho:
    PHP Code:
    bashcalcommand not found 
    and the + signs are created rather slow
    still it doesn't take away the fact that colors make your shell a better place to work in

  3. #3
    Join Date
    Jul 2007
    Location
    Austria
    Posts
    1,336
    Quote Originally Posted by wpte View Post
    looks good newbie fan

    this line pops up tho:
    PHP Code:
    bashcalcommand not found 
    and the + signs are created rather slow
    still it doesn't take away the fact that colors make your shell a better place to work in
    Bet, your system is not up to date: my cal works!

    Hehe, regarding signs: make them faster!! You're the man!

    helmut
    Alle HowTo's, all howto's

    RT-N16 1.9.2.7-rtn-r3121, Samba, VSFTP, Lightthpd, PHP, Perl, MySQL, Serendipity, Aria2web, HDD 640GB
    RT-N66U, 16GB MicroSD/ 2 Partitions, 2,5" HDD 1TB, running with Merlin's FW and Entware, 16 Mbit A1,
    Netgear DGND 3700V2, QNAP TS119PII 4 TB, QNAP TS209 2 TB Raid1, Backup Synology DS107+ 1 TB, HP CP1515n

Similar Threads

  1. bash (shell)
    By Mam(O)n in forum Russian Discussion - РУССКИЙ (RU)
    Replies: 126
    Last Post: 23-12-2014, 16:35
  2. ipkg-Web-Managment cgi-bin Script von NSLU2 auf WL-HDD + ASUS umbauen
    By WLAN-Fan in forum German Discussion - Deutsch (DE)
    Replies: 62
    Last Post: 03-01-2011, 18:08
  3. [HowTo] Bash beliebig erweitern
    By newbiefan in forum German Discussion - Deutsch (DE)
    Replies: 3
    Last Post: 01-11-2009, 15:23
  4. Can I give root the bash shell? Savely...?
    By mumsoft in forum WL-700g Q&A
    Replies: 0
    Last Post: 08-08-2007, 15:10
  5. [HOWTO] Wondershaper
    By Calvin in forum German Discussion - Deutsch (DE)
    Replies: 2
    Last Post: 03-09-2006, 09:42

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •