1

Say I've been working on the same project for the past few weeks, every day I like to start with a fresh terminal. This means I always start with cd /path/to/project.

When working with iTerm2 on the Mac, I very much enjoy the option to show my most frequently (and recently) used directories. Described here under 'Recent Directories'.

A quick keystroke and a pop-up appears allowing me to complete a directory path after typing cd.

Is there anything in Ubuntu which can match this behaviour?

LondonRob
  • 355
  • 4
  • 19

1 Answers1

3

There are some options.

1. Fuzzy finder

A utility, fuzzy finder, will do exactly what you want. Fuzzy finder is in the Ubuntu repositories (at least as of 19.04) and can be installed with

sudo apt get install fzf

Alternatively, it can be installed from its github page.

Once installed, at the prompt, press Alt+c. You immediatelly can start typing the name of a folder underneath the folder where you are. When the name appears, select it and press Enter to cd into it.

WHen typing a command, Ctrl+T will allow you to search and put any name of a folder or file on the command line.

2. Your bash history

  • Type Ctrl+r: this starts reverse search in your history
  • type pro (i.e. the actual name of your project): likely, you recent command cd /path/to/project will already have popped up.
  • Press Enter to execute the command

This will reduce your effort to four, five keystrokes. If another matching (more recent) command pops up, press Ctrl+r again to continue the reverse search.

Also typing just cd after Ctrl+r already will list the last cd command used. Continue pressing Ctrl+r to cycle through previous cd commands. However, the chance that your folder name is more unique and thus is found quicker, is higher.

3. Rofi or dmenu

With rofi or dmenu, you can easily create small menu's that dynamically represent your recent folders. rofi (or dmenu) takes a text file as input for menu items. The output of the command history | grep cd can be displayed to you through rofi as following:

history | grep cd | rofi -dmenu

Place this in a small script, and bind a hotkey to it. The hotkey will now display all your recent cd commands. Type a few letters of the directory to narrow down the list.

4. Other options

  • Make aliases to the commands you know you will be repeating
  • Make small scripts to run the commands you know will be repeating
vanadium
  • 88,010
  • More options: shell function, partial command history search – wjandrea Jan 04 '19 at 14:51
  • Yes, this is not bad. I know about ctrl+R but it assumes you already know the name of the directory you want to go to. I enjoyed not having to think too hard, and just seeing my most recently/commonly visited directories. Maybe there is no way. – LondonRob Jan 04 '19 at 15:29
  • I would assume you know part of the folder name if you frequently visit the folder using the terminal. Anyway, typing "cd" and searching backwards will cycle through all your recent cd command. history | grep cd will list them all. Again, you can put this in an alias. One step further is to script that as input for the rofi menu, and bind that script to a hotkey. With one hotkey, you would then list all your recent cd commands and be able to select and run one with arrow keys and Enter. – vanadium Jan 04 '19 at 16:14