- Add the function to your
.bashrc
,.bash_profile
,.bash_functions
,.zshrc
or whatever else is used in your shell. - Adjust the second line,
cd ~/workspace
, with acd
to your workspace directory - Done!
Last active
April 15, 2016 11:06
-
-
Save KevinGimbel/e23c6781e0849c7fef157f920b777574 to your computer and use it in GitHub Desktop.
switch to workspace or sub directory if available
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
# Switch to workspace or directly into a workspace directory if any is found | |
function ws() { | |
# $1 is the target directory | |
target_dir=$1 | |
# We start searching from the workspace dir, you need to adjust this when | |
# adding the script to your own .bash_profile or .bashrc | |
cd ~/workspace | |
# -maxdepth is the max directories to go "down" | |
# head -n1 gives back the first result | |
workspace_path=$(find -maxdepth 3 -type d -name "*$target_dir*" | head -n1) | |
if [ -z "$workspace_path" ]; then | |
echo "Directory '$target_dir' not found. Changing to ~/workspace" | |
else | |
cd "$workspace_path" | |
fi | |
} |
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 is a example file structure of my ~/workspace directory | |
├── adminer | |
│ └── index.php | |
├── bullgit | |
│ └── talk | |
├── github | |
│ ├── atom-branch-check | |
│ ├── hype | |
│ ├── jekyll-project-page-starter | |
│ ├── keepass-node | |
│ ├── KevinGimbel_CMSUi | |
│ ├── kevingimbel.github.io | |
│ ├── postgen | |
│ └── viewSwitcher | |
├── go | |
│ ├── bin | |
│ ├── pkg | |
│ └── src | |
├── jsfeatures | |
│ ├── cli | |
│ ├── lib | |
│ └── server | |
├── linedup | |
│ ├── assets | |
│ ├── cli | |
│ └── web | |
├── lunch-break.cooking | |
│ ├── [...] | |
├── polymer | |
│ └── polymer-lessons | |
├── rates | |
│ ├── models | |
│ ├── node_modules | |
│ ├── package.json | |
│ ├── public | |
│ ├── routes | |
│ ├── server.js | |
│ ├── src | |
│ └── views | |
├── react-native | |
│ └── Test | |
├── r.kevingimbel.me | |
│ ├── config.sample.js | |
│ ├── node_modules | |
│ ├── package.json | |
│ ├── public | |
│ ├── README.md | |
│ ├── server.js | |
│ └── src | |
├── sw | |
│ ├── node_modules | |
│ ├── package.json | |
│ ├── public | |
│ ├── routes | |
│ ├── server.js | |
│ └── views | |
├── synoa | |
│ ├── bug.industries | |
│ ├── dev.bug.industries | |
│ ├── magento | |
│ ├── synoa.github.io | |
│ └── wordpress | |
└── test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment