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

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
  • 97,564