zsh: add mkcd()

This commit is contained in:
Fernando Schauenburg 2023-07-15 00:32:24 +02:00
parent f650ed74b5
commit bfa78813c9
2 changed files with 13 additions and 0 deletions

View file

@ -4,6 +4,7 @@ source "$ZDOTDIR/completion.zsh"
source "$ZDOTDIR/history.zsh"
source "$ZDOTDIR/prompt.zsh"
source "$ZDOTDIR/vi-mode.zsh"
source "$ZDOTDIR/functions.zsh"
# Prevent ctrl-s from freezing the terminal.
stty stop undef

12
config/zsh/functions.zsh Normal file
View file

@ -0,0 +1,12 @@
# Source: https://unix.stackexchange.com/a/9124
mkcd() {
case "$1" in
*/..|*/../) cd -- "$1" ;;
/*/../*) (cd "${1%/../*}/.." && mkdir -vp "./${1##*/../}") && cd -- "$1" ;;
/*) mkdir -vp "$1" && cd "$1" ;;
*/../*) (cd "./${1%/../*}/.." && mkdir -vp "./${1##*/../}") && cd "./$1";;
../*) (cd .. && mkdir -vp "${1#.}") && cd "$1" ;;
*) mkdir -vp "./$1" && cd "./$1";;
esac
}