Search for history commands when pressing up button in terminal

Hi. I'm new here, coming from a Linux background. Bought my first Macbook Pro few days ago.

When opening a terminal, and pressing "up" button, I expect that the terminal returns only those commands which start with the text already written.


For example:

When I write "ssh" and press the "up" key, I expect to see only ssh commands in my history.

I've managed to implement this with (inside .inputrc) from AskUbuntu.


## arrow up
"\e[A":history-search-backward
## arrow down
"\e[B":history-search-forward


IMHO, this should be the default behaviour. What do you think?


EDIT:

now I see that the similar question was already asked

MacBook Pro with Retina display, null

Posted on Mar 10, 2016 12:32 AM

Reply
14 replies

Mar 11, 2016 10:30 AM in response to warriorkitty

warriorkitty wrote:

Actually, Apple could easily put ~/.inputrc by-default in the filesystem.

I think you want Apple to create an /etc/inputrc, not pollute every user account with a $HOME/.inputrc


But also consider that Apple DOES NOT CARE about the command line environment. The command line is not where Apple spends their money. They are creating a point and click GUI operating system that just happens to run on top of a Unix underside. Apple ONLY does what it absolutely has to in the command line environment.


If you want to live in the command line environment, then you had better start looking at doing your own customization's, building your own open source packages, or using one of the above mentioned package managers to create the environment you want. Or run a virtual machine and load your preferred Linux distribution.


Also note, Linux is not the only Unix like environment. If you want to unify the Unix world to have a consistent command line interface, they you also need to notify AIX, HP-UX, Solaris as an example of some major players (I would personally appreciate it as I either work on those platforms, or have had to suffer with them in the past). Then again, many of things you would want from Linux, the GNU Foundation has forbidden these vendors use, as the GPLv3 license is a poison pill, that they cannot swallow. So you are again back to rolling your own on any platform that is not Linux. Trust me, I've been there for the past 20+ years.


But definitely submit your feedback to Apple

<http://www.apple.com/feedback>

Mar 11, 2016 5:00 PM in response to Tony T1

If I understood you correctly, then this is a deal-breaker for me.

I was connected through SSH to 3-4 different IP addresses. I don't want just the autocomplete for the SSH, I want to be able to reconnect (loop through) my last SSH IP addresses so taking history into account is a 'must' for me.


That's the reason why this is perfect for me:


  1. ## arrow up
  2. "\e[A":history-search-backward
  3. ## arrow down
  4. "\e[B":history-search-forward

Mar 11, 2016 5:52 PM in response to warriorkitty

warriorkitty wrote:


If I understood you correctly, then this is a deal-breaker for me.

I was connected through SSH to 3-4 different IP addresses. I don't want just the autocomplete for the SSH, I want to be able to reconnect (loop through) my last SSH IP addresses so taking history into account is a 'must' for me.


That's the reason why this is perfect for me:


  1. ## arrow up
  2. "\e[A":history-search-backward
  3. ## arrow down
  4. "\e[B":history-search-forward

I do not understand what you are saying with respect to ssh. ssh will just be forwarding your keyboard input to the remote node, which I'm assuming is running a shell that has its own inputrc configuration.


ssh does not have autocomplete, nor readline, nor inputrc integration. ssh is just a tool for connecting to a remote system in a secure manor.


At the remote node you get to run a shell that can have readline and inputrc.

Mar 10, 2016 4:55 PM in response to warriorkitty

You are running 'bash' with 'readline' as the command line editing functionality. It is NOT code written by Apple.


And ever since GPL V3 license was released and applied to things like bash and readline, Apple has been prevented from including newer versions of bash and readline in its products.


So you should be looking at the 'man bash' and 'man readline' for how to configure your command line editing features.


If you want the latest versions of bash and readline, then you will need to install your own version. You can download the sources, compile and install then. Or you can use one of the OS X packages managers.

<http://www.finkproject.org/> puts builds in /sw/...

<http://www.macports.org/> puts builds in /opt/local/...

<http://brew.sh/> puts builds in /usr/local/...

Mar 11, 2016 11:52 AM in response to warriorkitty

warriorkitty wrote:


You are absolutely right. I spent too much time with Linux and in the terminal. 🙂

It pays the bills, and I do use a 27" iMac as my workstation, with iTerm2 as my terminal emulator, with 25 ssh sessions (at the moment) into other Unix platforms, plus about 10 local shell sessions.


A 27" iMac, with a 24" attached monitor gives me lots of room for terminal sessions. My .bashrc and .bash_profile are a bit complex because I use the exact same shell initialization files on ALL of those Unix platforms. You get to really see how different implementations differ.

Mar 12, 2016 12:11 PM in response to warriorkitty

I was connected through SSH to 3-4 different IP addresses. I don't want just the autocomplete for the SSH, I want to be able to reconnect (loop through) my last SSH IP addresses so taking history into account is a 'must' for me.


Think about this a little more. Only data from a bash read goes to the history file. bash puts up a read. You type in the ssh command. bash gets the command. bash puts the data inputted into the history file. bash parses the data. bash invokes ssh. ssh connects to a remote system. Once connected, ssh puts up a read to your terminal. You will notice this is a read from ssh not from bash. The read data for ssh goes to the remote session.


You could try

-- linking to a common history file on some server,


-- Modifying the ssh command to add data to the history file.


Would this work?


R

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Search for history commands when pressing up button in terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.