Skip to content

Instantly share code, notes, and snippets.

@tommyjtl
Created January 14, 2024 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommyjtl/9c283d95c0c6691972f156139e2431d7 to your computer and use it in GitHub Desktop.
Save tommyjtl/9c283d95c0c6691972f156139e2431d7 to your computer and use it in GitHub Desktop.
A bash function command that quickly takes me to certain directory.
enter() {
local config_dir="$HOME/.config/enter"
local config_file="$config_dir/enter.yml"
# Initialize configuration
if [ ! -d "$config_dir" ]; then
mkdir -p "$config_dir"
fi
if [ ! -f "$config_file" ]; then
local user_root=$(pwd )
echo "root: $HOME" > "$config_file"
fi
# List directories
if [ "$1" == "-l" ]; then
cat "$config_file"
return
fi
# Create quick command
if [ "$1" == "-c" ]; then
read -p "Enter a short name for this directory: " short_name
echo "$short_name: $(pwd)" >> "$config_file"
return
fi
# Navigate to directory
if [ -n "$1" ]; then
local dir=$(grep "^$1:" "$config_file" | cut -d ' ' -f 2-)
if [ -n "$dir" ]; then
cd "$dir"
else
echo "Directory not found for: $1"
fi
return
fi
echo "Usage: enter [-l | -c | <short_name>]"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment