diff --git a/fish_helpers.fish b/fish_helpers.fish index 5e06ca0..3c0c9ba 100644 --- a/fish_helpers.fish +++ b/fish_helpers.fish @@ -1,9 +1,15 @@ function temptree + if contains -- -h $argv; or contains -- --help $argv + command temptree $argv; return + end set -l dir (command temptree $argv); or return test -d "$dir" && cd $dir end function rmtree + if contains -- -h $argv; or contains -- --help $argv + command rmtree $argv; return + end set -l has_path false for arg in $argv switch $arg diff --git a/nushell_helpers.nu b/nushell_helpers.nu index ef42d88..4b9846e 100644 --- a/nushell_helpers.nu +++ b/nushell_helpers.nu @@ -1,4 +1,7 @@ def --env temptree [...args: string] { + if ($args | any {|a| $a == "-h" or $a == "--help"}) { + ^temptree ...$args; return + } let dir = (^temptree ...$args) if ($dir | is-not-empty) and ($dir | path type) == "dir" { cd $dir @@ -6,6 +9,9 @@ def --env temptree [...args: string] { } def --env rmtree [...args: string] { + if ($args | any {|a| $a == "-h" or $a == "--help"}) { + ^rmtree ...$args; return + } let has_path = ($args | any {|a| $a == "--" or not ($a starts-with "-")}) let dir = (^rmtree ...$args) if not $has_path and ($dir | is-not-empty) and ($dir | path type) == "dir" { diff --git a/shell_helpers.sh b/shell_helpers.sh index 069ad25..650ae93 100644 --- a/shell_helpers.sh +++ b/shell_helpers.sh @@ -1,11 +1,13 @@ # shellcheck shell=bash temptree() { + case "$*" in *-h*|*--help*) command temptree "$@"; return ;; esac local dir dir="$(command temptree "$@")" || return [[ -d "$dir" ]] && builtin cd "$dir" } rmtree() { + case "$*" in *-h*|*--help*) command rmtree "$@"; return ;; esac local dir has_path=false arg for arg in "$@"; do case "$arg" in diff --git a/temptree b/temptree index 69f363f..6f6c610 100755 --- a/temptree +++ b/temptree @@ -26,6 +26,8 @@ die() { [[ -z "${TEMPTREE_FOREST_DIR:-}" || "$forest_dir" == /* ]] \ || die "TEMPTREE_FOREST_DIR must be an absolute path" +case "${1:-}" in -h|--help) usage; exit 0 ;; esac + repo_root="$(git rev-parse --show-toplevel 2>/dev/null)" \ || die "not inside a git repository" main_worktree="$(git worktree list --porcelain | head -1)"