The ⌘-k "access anything" shortcut is awesome on Notion, Slack, etc.
The terminal, by comparison, is a dinosaur: tons of repeated cd
and ls
and TAB
just to get anywhere.
This is ⌘-k for the terminal: access anything on your filesystem, from anywhere, with previews before you open:
When you press enter, the type of selected files are identified and...
- Directories get
cd
d to - Text files get opened in the command of your
$EDITOR
variable (orvim -O
if it's unset) - Images and PDFs get opened in the Preview app
.key
files get opened in Keynote
I'm extremely grateful to fzf; this project wouldn't be possible without it. I'd been fed up with terminal navigation for a decade, and fzf was the missing piece needed to make cmdk possible.
-
Install
cmdk
and dependencies:# NOTE: 'bat', 'tiv', and 'poppler' are optional: for previewing text, image, and PDF files respectively brew install fzf fd bat tiv poppler
-
git clone https://github.com/mieubrisse/cmdk.git ~/.cmdk
-
Add to your
.zshrc
or.bashrc
:source ~/.cmdk/cmdk.sh # Provides a 'cmdk' function in your shell
Or if you're on
fish
, to your~/.config/fish/config.fish
:source ~/.cmdk/cmdk.fish
-
(Optional) Bind the
⌘-k
hotkey (or any other if you prefer) to send the textcmdk\n
in your terminal:💻 iTerm
Settings → Profiles → Keys → Keybindings → + → Send Text
, then binding⌘-k
to send the textcmdk\n
👻 Ghostty
# ~/.config/ghostty/config (or $XDG_CONFIG_HOME/ghostty/config) keybind = cmd+k=text:cmdk\r
-
Open a new shell and press your hotkey (⌘-K if you bound it) or enter
cmdk
(if you don't have a hotkey) -
(Optional) If you'd like to use
cmdk
's functionality withfzf
's , add the following to your.bashrc
or.zshrc
:export FZF_CTRL_T_COMMAND="bash ${HOME}/.cmdk/list-files.sh" export FZF_CTRL_T_OPTS="-m --ansi --scheme=path --preview='bash ${HOME}/.cmdk/preview.sh {}'"
TODO
fish
Press ⌘-k (or type cmdk
) and...
- Type to start filtering
💡 If you're trying to get a directory, add a
/
to the end of your search term. E.g.down/
will pull up theDownloads
directory Ctrl-j
andCtrl-k
to scroll up and down the results listENTER
to select the resultTAB
to select multiple items beforeENTER
Ctrl-u
to clear the selection
⚠️ Some directories likeLibrary
,/
, and.git
are full of stuff users don't need to access, so their contents are excluded. To get to their contents, first ⌘-k to them and then ⌘-k again to see their contents.
💡 Sometimes you only want to jump to the contents of the current directory. This can be done by calling
cmdk -o
to list only the contents of the current directory (no recursing) orcmdk -s
to list subdirectories (recursing). I've set up separate iTerm hotkeys:⌘-k
to sendcmdk\n
, and⌘-shift-k
forcmdk -s\n
.
-o
- Only list the contents of the current directory at depth 1 (original behavior)-s
- List all contents of the current directory recursively, including subdirectories
Hi HN! I'd love to hear how you're using cmdk, and making it your own.