From bfa78813c9ee1625ceff2afff401a79ee3b6ee82 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Sat, 15 Jul 2023 00:32:24 +0200 Subject: [PATCH] zsh: add mkcd() --- config/zsh/.zshrc | 1 + config/zsh/functions.zsh | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 config/zsh/functions.zsh diff --git a/config/zsh/.zshrc b/config/zsh/.zshrc index c66bbac..d538d81 100644 --- a/config/zsh/.zshrc +++ b/config/zsh/.zshrc @@ -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 diff --git a/config/zsh/functions.zsh b/config/zsh/functions.zsh new file mode 100644 index 0000000..e15b6ef --- /dev/null +++ b/config/zsh/functions.zsh @@ -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 +} +