Files
fish-config/functions/mkcd.fish
T
Claude fceddfc43f docs: add DEPENDENCIES sections to function doc headers
Documents what each function needs for full functionality -- other
repo functions it calls, and external CLI tools it uses or falls
back gracefully without (e.g. rm/trash, ls/eza+lsd) -- matching the
existing CLASSIFICATION convention's placement and the ~20 functions
that already carried this label.

Also broadens verify-manual.py's dependency-resolution check to
recognize this repo's other existence-check idioms (command -q,
command -v, which -- not just type -q) and dng2avif's dynamic
type -q $cmd loop, since several genuine dependencies (eza, lsd,
fastfetch, fd, ps, ...) are only ever guarded that way.
2026-09-22 22:22:27 -04:00

83 lines
2.4 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# CATEGORY
# 01-file-and-directory
#
# DEPENDENCIES
# _fish_mkdir_p
#
# CLASSIFICATION
# bypasses-shadow(cd)
#
# SYNOPSIS
# mkcd [-s | --silent] <dir>
#
# DESCRIPTION
# Creates a directory (including any missing parent directories) and
# immediately changes into it. Prints a tree of created directories by
# default, or suppresses output with -s. Delegates creation to
# _fish_mkdir_p.
#
# ARGUMENTS
# -h, --help Show usage help
# -s, --silent Suppress directory creation output
# <dir> Directory to create and enter
#
# EXIT STATUS
# 0 Directory created (or already existed) and entered successfully
# 1 Directory creation or cd failed
#
# EXAMPLE
# mkcd ~/projects/myapp
# mkcd ~/projects/newapp/src
function mkcd --description 'Create a directory (with parents) and cd into it'
__fish_palette
if contains -- -h $argv; or contains -- --help $argv; or test (count $argv) -eq 0
echo "$c_head""Usage:$c_reset $c_cmd""mkcd$c_reset $c_arg""<dir>$c_reset"
echo
echo " Create $c_arg""<dir>$c_reset (including missing parents) and cd into it."
echo
echo "$c_head""Arguments:$c_reset"
echo " $c_arg""<dir>$c_reset Directory to create and enter"
echo
echo "$c_head""Flags:$c_reset"
echo " $c_flag-h$c_reset, $c_flag--help$c_reset Show this help message"
echo " $c_flag-s$c_reset, $c_flag--silent$c_reset Suppress directory creation output"
echo
echo "$c_head""Examples:$c_reset"
echo " $c_cmd""mkcd$c_reset $c_arg~/projects/myapp$c_reset"
echo " $c_cmd""mkcd$c_reset $c_arg~/projects/myapp$c_reset""$c_dim""; git init$c_reset"
return 0
end
set -l silent 0
set -l dir
for _arg in $argv
switch $_arg
case -s --silent
set silent 1
case '*'
set dir $_arg
end
end
set -l is_new 0
test -d $dir; or set is_new 1
if test $silent -eq 1
_fish_mkdir_p --silent $dir; or return $status
else
_fish_mkdir_p --tree $dir; or return $status
end
builtin cd $dir
or return $status
if test $is_new -eq 1
echo "$c_ok""✔$c_reset Created and entered $c_arg$dir$c_reset"
else
echo "$c_warn""→$c_reset $c_arg$dir$c_reset already exists — entered"
end
end