2018-03-05 14:25:25 +00:00
|
|
|
# Generates a list of parent directories for a given path
|
|
|
|
# i.e. /a/b/c/d -> [/a/b/c/, /a/b/, /a/, and /a]
|
|
|
|
function __fish_parent_directories
|
2019-05-05 10:09:25 +00:00
|
|
|
if test (count $argv) -ne 1
|
|
|
|
# for use in completions, so don't spew error messages
|
|
|
|
return 1
|
|
|
|
end
|
2018-03-05 14:25:25 +00:00
|
|
|
|
2019-05-05 10:09:25 +00:00
|
|
|
set -l splits (string split '/' $argv[1])
|
|
|
|
set -l parents
|
2018-03-05 14:25:25 +00:00
|
|
|
|
2019-05-05 10:09:25 +00:00
|
|
|
for split in $splits
|
|
|
|
if test (string length "$split") -eq 0
|
|
|
|
continue
|
|
|
|
end
|
2018-03-05 14:25:25 +00:00
|
|
|
|
2019-05-05 10:09:25 +00:00
|
|
|
set parents "$parents[1]/$split" $parents
|
|
|
|
end
|
2018-03-05 14:25:25 +00:00
|
|
|
|
2019-05-05 10:09:25 +00:00
|
|
|
for parent in $parents
|
|
|
|
echo $parent
|
|
|
|
end
|
2018-03-05 14:25:25 +00:00
|
|
|
|
2019-05-05 10:09:25 +00:00
|
|
|
return 0
|
2018-03-05 14:25:25 +00:00
|
|
|
end
|