feat(shell): integrate _fish_mkdir_p into mkdir and mkcd
- mkdir: loop over path args calling _fish_mkdir_p --path; falls back to command mkdir -p when flag args (e.g. -m 755) are present - mkcd: default to _fish_mkdir_p --tree for new dirs; add -s/--silent flag to suppress tree output (mkcd's own status message still prints)
This commit is contained in:
@@ -44,12 +44,12 @@ function _fish_mkdir_p --description 'mkdir -p with configurable verbose output'
|
||||
|
||||
if test $mode = path
|
||||
set -l display (string replace -- "$HOME" "~" $target)"/"
|
||||
echo (set_color --bold cyan)"Created: "(set_color cyan)"$display"(set_color normal)
|
||||
echo (set_color --bold cyan)"Created directory: "(set_color cyan)"$display"(set_color normal)
|
||||
return 0
|
||||
end
|
||||
|
||||
# Tree mode: dimmed existing anchor, then cyan new dirs.
|
||||
echo (set_color --bold cyan)"Created missing directories:"(set_color normal)
|
||||
echo (set_color --bold yellow)"Created directories:"(set_color normal)
|
||||
set -l anchor (string replace -- "$HOME" "~" $cursor)"/"
|
||||
echo (set_color brblack)" $anchor"(set_color normal)
|
||||
set -l i 1
|
||||
|
||||
+16
-5
@@ -22,6 +22,7 @@ function mkcd --description 'Create a directory (with parents) and cd into it'
|
||||
echo
|
||||
echo "$c_head""Flags:$c_rst"
|
||||
echo " $c_flag-h$c_rst, $c_flag--help$c_rst Show this help message"
|
||||
echo " $c_flag-s$c_rst, $c_flag--silent$c_rst Suppress directory creation output"
|
||||
echo
|
||||
echo "$c_head""Examples:$c_rst"
|
||||
echo " $c_cmd""mkcd$c_rst $c_arg~/projects/myapp$c_rst"
|
||||
@@ -29,13 +30,23 @@ function mkcd --description 'Create a directory (with parents) and cd into it'
|
||||
return 0
|
||||
end
|
||||
|
||||
set -l dir $argv[1]
|
||||
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
|
||||
if not test -d $dir
|
||||
set is_new 1
|
||||
command mkdir -p $dir
|
||||
or return $status
|
||||
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
|
||||
|
||||
+10
-1
@@ -4,7 +4,16 @@
|
||||
# Execute mkdir
|
||||
function mkdir --description 'Execute mkdir'
|
||||
if status is-interactive
|
||||
command mkdir -p $argv
|
||||
# Fall back to command mkdir -p when flags are present (e.g. -m 755)
|
||||
for _arg in $argv
|
||||
if string match -q -- '-*' $_arg
|
||||
command mkdir -p $argv
|
||||
return $status
|
||||
end
|
||||
end
|
||||
for _dir in $argv
|
||||
_fish_mkdir_p --path $_dir
|
||||
end
|
||||
else
|
||||
command mkdir $argv
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user