Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions fish_helpers.fish
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions nushell_helpers.nu
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
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
}
}

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" {
Expand Down
2 changes: 2 additions & 0 deletions shell_helpers.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions temptree
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down