Files
fish-config/functions/mkcd.fish
T
rootiest 7d815b17e8 refactor: retire drifted palette names in the last five functions
c_rst/c_txt -> c_reset, c_ttl -> c_head, c_bold -> c_cmd, c_primary -> c_arg
across 67 interpolation sites (c_rst 53, c_primary 10, c_bold 2, c_ttl 1,
c_txt 1). Each maps to a variable holding identical bytes, so output is
unchanged. Unlike the 33 structural conversions this edits text that
renders, so it is gated on its own per-file byte-diff against main:

  ok  logs --help         (431 B out, 0 B err)
  ok  mkcd --help         (437 B out, 0 B err)
  ok  qc --help           (936 B out, 0 B err)
  ok  rand_string --help  (883 B out, 0 B err)
  ok  smart_exit --help   (265 B out, 0 B err)
  ok  mkcd                (437 B out, 0 B err)   <- no-args error path

c_accent is deliberately NOT merged into c_ok -- both are (set_color green)
but a role is a semantic slot, not a colour. See JOB-BRIEF-FINDINGS.md.

logs.fish needed two calls (the C4 guard block and the --help block, both at
8-space indentation); it is the only multi-run file in the repository and the
exact trap a depth-deduplicating converter falls into. logs.fish also declared
c_bold without ever interpolating it -- that declaration is simply deleted.
2026-09-07 20:10:43 -04:00

77 lines
2.3 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# CATEGORY
# 01-file-and-directory
#
# 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
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