Last active
May 14, 2024 09:58
-
-
Save 1kko/c1ef1afc7cbfb8712146bbe3a767d395 to your computer and use it in GitHub Desktop.
Bash - performs search of specific directory up to 2 depth and change directory into it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script performs search of specific directory up to 2 depth and change directory into it. | |
# This is helpful for cases like having many repositories and need to cd into it. | |
# Install | |
# 1. Install fzf(https://github.com/junegunn/fzf#related-projects). eg: sudo apt install fzf ( | |
# 2. Copy this source and paste into paste into your: nano ~/.bashrc | |
# 3. Edit the srchDir variable for your environment | |
# 4. Save and start new session of terminal | |
# Usage | |
# $ repo term1 term2 | |
# Script | |
# Copy from bottom line to end and paste in the end of ~/.bashrc | |
repo() { | |
# This will list up to 2 depth of given directory. Add/remove '*/' to your preferences. | |
# The path should be absolute path. | |
# Note that too many depth will slow-down the script, less depth will show fewer results. | |
local srchDir="/home/your/repo/*/*/" | |
# if any arguments arn't given, just list up everything else use search query | |
[ "$1" = false ] && cd "$(ls -d $srchDir | fzf)" || local qTerm="${@}"; cd "$(ls -d $srchDir | fzf -q "$qTerm")" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is how it works
