Last active
October 8, 2016 11:50
-
-
Save Mic92/1cc866df56154027aae9438d19e657e1 to your computer and use it in GitHub Desktop.
zshrc clever functions
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
# cd to files' directories | |
cd() { | |
local to="${1:-$HOME}" | |
if [ -f "$to" ]; then | |
to="$(dirname $to)" | |
fi | |
builtin cd "$to" | |
} |
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
upfind() { | |
local previous= | |
local current=$PWD | |
if [[ $# -ne 1 ]];then | |
echo "$0 FILE_NAME" | |
return 1 | |
fi | |
while [[ -d $current && $current != $previous ]]; do | |
local target_path=$current/$1 | |
if [[ -f $target_path ]]; then | |
echo $target_path | |
return 0 | |
else | |
previous=$current | |
current=$current:h | |
fi | |
done | |
return 1 | |
} | |
# build project from subdirectory | |
ninja(){ | |
local build_path="$(dirname "$(upfind "build.ninja")")" | |
command ninja -C "${build_path:-.}" "$@" | |
} | |
make(){ | |
local build_path="$(dirname "$(upfind "Makefile")")" | |
command make -C "${build_path:-.}" "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment