1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to enable history-search-backward and history-search-forward

Discussion in 'Tomato Firmware' started by darksky, Aug 26, 2013.

  1. darksky

    darksky Networkin' Nut Member

    On my workstation, I added the following to /etc/inputrc which allow for partial history matches with up arrow/down arrow:

    Code:
    "\e[A":history-search-backward
    "\e[B":history-search-forward
    
    I tried adding the same lines to /tmp/home/root/.inputrc but it doesn't get called. How can I enable them on my Tomato's shell? Thanks!
     
  2. koitsu

    koitsu Network Guru Member

    Busybox sh (a.k.a. "ash" -- do not confuse it with Debian ash) does not support such things. You will need to use real/true bash, available via Entware.

    Edit: When I say Entware, I do mean Entware, and not Optware. I say this here because you also made this thread as well, indicating you use Optware:

    http://www.linksysinfo.org/index.php?threads/optware-freshness-a-more-up-to-date-mirror.68939/

    bash on there (for me anyway) was known to do very wrong/stupid things to the environment (such as tinkering with LD_LIBRARY_PATH), while on Entware this is is accomplished properly using the rpath feature of ld.so/linker. @ryzhov_al and others who maintain Entware are a good set of folks who know what they're doing. :)

    And do not mix the two (Entware and Optware). You will need to completely delete all of your Optware installation (including files starting with periods -- there are some, believe it or not) when moving from one to another. Start fresh. I cannot stress this enough, as there have already been threads in the past where someone tried to "move from Optware to Entware" and didn't delete everything fully and caused themselves a lot of pain/reported "issues" which were due to what I just said.
     
    Last edited: Aug 26, 2013
  3. darksky

    darksky Networkin' Nut Member

    Ha, thanks for the warning. I am actually googling around now for a optware-->entware conversion guide. Perhaps the best course of action is simply to archive the optware and re-create by hand the needed files as you suggested.
     
    Marcel Tunks likes this.
  4. darksky

    darksky Networkin' Nut Member

    I now have entware installed. I also installed bash via opkg. When I come into the router, I have to switch shells to bash:

    Code:
    # bash -
    My ~/.inputrc cannot seem to get understood:
    Code:
    # source ~/.inputrc
    bash: \e[A:history-search-backward: command not found
    bash: \e[B:history-search-forward: command not found
    Any advice is welcomed.
     
  5. koitsu

    koitsu Network Guru Member

    You don't understand how .inputrc works. You don't source it; it doesn't contain shell commands. Why do you think it does? :)

    Please read the bash man page for details on how it works (search for the phrase "Readline Initialization"). Then go read the GNU bash documentation, specifically this section. Do not skim the section, READ IT; it does contain the answer to your question (hint: bind command).
     
  6. darksky

    darksky Networkin' Nut Member

    OK, thanks. My problem was expecting this to work with the builtin /bin/sh. Last question... is changing one's default shell to /opt/bin/bash recommended? I don't see a chsh util. What is the recommended way that covers cases where the USB may not be present?

    Code:
    # cat ~/.inputrc
    "\e[A":history-search-backward
    "\e[B":history-search-forward
    
    # cat ~/.bash_profile
    set -o vi
    alias xx='exit'
    alias ls='ls --color=always'
    alias ll='ls -lh'
    alias la='ls -lha'
    alias lt='ls -lhtr'
    alias lta='ls -lhatr'
    alias ..='cd ..'
    alias ...='cd ../..'
    alias ....='cd ../../..'
    
    # cat ~/.profile
    set -o vi
    alias xx='exit'
    alias ls='ls --color=always'
    alias ll='ls -lh'
    alias la='ls -lha'
    alias lt='ls -lhtr'
    alias lta='ls -lhatr'
    alias ..='cd ..'
    alias ...='cd ../..'
    alias ....='cd ../../..'
    [[ -x /opt/bin/zsh ]] && /opt/bin/zsh
    
     
    Last edited: Aug 27, 2013
  7. koitsu

    koitsu Network Guru Member

    Really quite simple: type bash any time you want it, barring situations where the USB storage device is unavailable. When done, just type exit to go back to the standard Busybox shell. I've grown used to doing this, and it ensures that I keep my stock/base environment (Busybox, Tomato, etc.) separate and "clean" from the Entware environment.

    You are welcome to modify /etc/passwd manually (say via sed) and replace root's shell with /opt/bin/bash if you wish, but as you've stated if the USB device is unavailable that's going to cause a serious problem.

    My advice is to stick with KISS principle and just type bash if/when you need it.
     
    jerrm likes this.
  8. darksky

    darksky Networkin' Nut Member

    The last line in my .profile accomplishes the same thing as modding /etc/passwd I think. But, I'd like to only type exit once.

    Also, I believe you want to use `bash --login` rather than bash so it sources the config files, no?
     
    Last edited: Aug 27, 2013
  9. lancethepants

    lancethepants Network Guru Member

    I run openssh along side dropbear on a different port. I've setup a different username and password with /opt as my home directory, and /opt/bin/bash as my environment.
    If USB for some reason fails to load, I can still access the router through ssh with dropber. Otherwise I'm always using the other username and it's environment.

    This explains my setup. You can stop short of the two factor authentication if that isn't desired.
    http://www.linksysinfo.org/index.php?threads/google-two-factor-authentication-on-tomato.68831/
     
  10. koitsu

    koitsu Network Guru Member

    No, the last line in your .profile does not. What you want to use is exec. exec is the proper solution for this task (read the first paragraph of the Description slowly/carefully) on every single level on *IX. Proof:
    Code:
    $ telnet gw
    Trying 192.168.1.1...
    Connected to gw.home.lan.
    Escape character is '^]'.
    gw login: root
    Password:
    
    
    Tomato v1.28.0502 MIPSR2Toastman-RT-N K26 USB Ext
    root@gw:/tmp/home/root# exec /opt/bin/bash
    root@gw:/tmp/home/root# echo $BASH_VERSION
    4.2.28(1)-release
    root@gw:/tmp/home/root# exit
    Connection closed by foreign host.
    
    No, you do not want to spawn a login shell; you already have one at that point. If you properly set up your dotfiles (specifically .bashrc and .bash_profile) then this is not an issue. Your aliases/etc. should go into .bashrc, and your .bash_profile (NOT .profile!) should have this in it:

    Code:
    if [ -f "${HOME}/.bashrc" ]; then
      source "${HOME}/.bashrc"
    fi
    
    The bash man page / documentation very clearly explains the difference between the two. It's a very long documentation section, but it's very concise. I should note when I read it, I had to read it 3 times to truly understand the intricacy, but now I do.

    But of course I also see you're using zsh, which has its own nuances and behaviour differences. I am not going to sit here trying to micro-manage "how to manage dotfiles" for three shells. This angers/upsets me.

    And your .inputrc is also still wrong (and you can get rid of that file entirely by placing proper commands into your .bashrc if you had read the bash Readline manual references I gave you -- you'd know what command you need to accomplish such).

    It never ceases to amaze me how many people mess up their dotfiles on *IX. It's remarkable. Even major Linux distributions get this stuff wrong, believe it or not. I think there's just a lack of transference of knowledge from us older UNIX people onto the younger generation, probably because the younger generation reads Ubuntu forum posts or random wonky answers they can find on Google rather than actually understanding how things work. This is one of many reasons why I hate technology/am a technophobe.

    @lancethepants method would also work.

    The key point here is that you want to keep the "main Busybox environment" as clean/untouched as possible, and to fully acknowledge that Tomato is not a replacement for a Linux workstation/desktop/server. Tomato is intended to be used as a router. The goals/intentions are very different.

    P.S. -- No I'm not in a good mood today for a lot of reasons, but I am growing fairly sick and tired of all these *IX questions on this forum; is stackoverflow just not in people's site vocabulary? :/ If people using the Tomato firmware and Entware haven't actually figured out how to distinguish the difference between what's Tomato vs. what's Entware vs. what's *IX, then all hope is lost. Rather than whine/cry, honestly I should just stay away from threads where there are *IX questions being asked. These just come up so often here that it pains me. But like I said, sorry, I'm not in a good mood today.
     
    Last edited: Aug 28, 2013
    Toastman likes this.
  11. darksky

    darksky Networkin' Nut Member

    I stand corrected and adjusted my ~/.profile to use exec, thank you for that suggestion. Only need to type exit once now!

    Code:
    # tail -n1 ~/.profile
    [[ -x /opt/bin/zsh ]] && exec /opt/bin/zsh
     

Share This Page