owenrusk.dev

dotfiles

shell, editor, ssh.

git clone https://owenrusk.dev/dotfiles.git

commit 7b08881ebaedf0c9febe1254bf89ab42460abfb2
parent 9e6d40205ef6af60e731233fa14da0facc16400f
author Owen Rusk <owen@papermothgames.com>
date   2024-08-08 13:15:56 -0500
zsh: mcd, up, top, x
zsh/functions.zsh+25-0
zsh/zshrc+1-0
diff --git a/zsh/functions.zsh b/zsh/functions.zsh
new file mode 100644
index 0000000..c502c0e
--- /dev/null
+++ b/zsh/functions.zsh
@@ -0,0 +1,25 @@
+# make a directory and go into it
+mcd() { mkdir -p -- "$1" && cd -- "$1" }
+
+# up 3 is cd ../../..
+up() {
+    local d=
+    repeat ${1:-1} d+=../
+    cd $d
+}
+
+# top of the current git repo
+top() { cd "$(git rev-parse --show-toplevel)" }
+
+# unpack whatever this is
+x() {
+    case $1 in
+        *.tar.gz|*.tgz) tar xzf $1 ;;
+        *.tar.xz) tar xJf $1 ;;
+        *.tar.zst) tar --zstd -xf $1 ;;
+        *.tar) tar xf $1 ;;
+        *.zip) unzip -q $1 ;;
+        *.gz) gunzip $1 ;;
+        *) echo "x: no idea what $1 is" >&2; return 1 ;;
+    esac
+}
diff --git a/zsh/zshrc b/zsh/zshrc
index 4a834de..7b164bd 100644
--- a/zsh/zshrc
+++ b/zsh/zshrc
@@ -35,5 +35,6 @@ PROMPT='%F{8}%m%f %F{blue}%~%f%F{yellow}${vcs_info_msg_0_}%f %(?..%F{red}%?%f )%
 # ~/.zshrc is a link. follow it back here.
 dots=${${(%):-%x}:A:h}
 source $dots/aliases.zsh
+source $dots/functions.zsh
 
 [[ -r ~/.zshrc.local ]] && source ~/.zshrc.local