Skip to content

Instantly share code, notes, and snippets.

@F-Baker
Last active October 1, 2023 13:44
Show Gist options
  • Save F-Baker/b50cc4da7f52fb9e814120fd262bc9dd to your computer and use it in GitHub Desktop.
Save F-Baker/b50cc4da7f52fb9e814120fd262bc9dd to your computer and use it in GitHub Desktop.

Mark and Recall

Description

This is quick pair of functions inspired by the "Elderscrolls III: Morrowind" traveling spells.

Objectives

Allow the user to mark and quickly return to an arbitrary location (i.e. file path) by typing a keyword.

Expected Outcomes

  • increased navigation speed to arbitrary locations.
    • E.G. I have a kubernetes object example directory buried within a private repo. Rather than spamming 'tab' to avoid typing the path, I can simply type mark to save the location and recall to return to it, regardless of the shell.

Setup

Here's a quick and dirty echo to add the functions to your .zshrc

echo "Adding mark and recall functions to $PWD/.zshrc"
echo "
# mark and recall functions for quick travel
function mark {
  echo $PWD >> ~/.mark_history
  echo $PWD
}

function recall {
  cd $(tail -n 1 ~/.mark_history)
}" >> ~/.zshrc && \
source ~/.zshrc

Usage

Mark

Once the functions have been added to your .zshrc, simply type mark in your console and the function will do the following:

  • the mark function writes the $PWD to an arbitrary file named .mark in your home directory
    • this allows the marked $PWD to be accessed in any shell with the the mark & recall functions loaded via .zshrc
    • mark runs cat on the newly created file for reference & confirmation of functionality.

Recall

Type recall into the console and the function runs a simple cd using the path written in ~/.mark

Caveats

  • only one location can be used

Disclaimer

This script is super duper simple so even if you run into problems, it should be easy to debug. It should work in bash but that hasn't been tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment