2023-01-04 01:28:50 +00:00
|
|
|
#!/usr/bin/env
|
|
|
|
|
|
|
|
function parent_dir
|
|
|
|
set -f trace (status stack-trace)
|
|
|
|
# By index:
|
|
|
|
# 1: in command substitution
|
|
|
|
# 2: parent.fish line
|
|
|
|
# 3: in function 'parent'
|
|
|
|
# 4: caller import line
|
|
|
|
# 5: in command substitution
|
|
|
|
# 6: caller "parent" invokation line
|
|
|
|
# 7: in function calling parent
|
|
|
|
# 8: jackpot! here's the parent of the caller
|
|
|
|
set -f parent_line $trace[8]
|
|
|
|
set -f parent_split (string split 'of file' $parent_line)
|
|
|
|
set -f parent (string trim $parent_split[2])
|
|
|
|
|
|
|
|
# qualify ~
|
|
|
|
set -f parent (string replace '~' "$HOME" $parent)
|
|
|
|
|
|
|
|
# Qualify the path to absolute and remove the filename
|
|
|
|
set -f parent_dir (realpath $parent)
|
|
|
|
set -f parent (string join '/' (string split '/' $parent_dir)[1..-2])
|
|
|
|
echo $parent
|
|
|
|
end
|
|
|
|
|
|
|
|
function import
|
|
|
|
set -f self_directory (parent_dir)
|
|
|
|
if set -q debug;
|
|
|
|
echo "importing $argv.fish from [$self_directory]"
|
|
|
|
end
|
2023-01-04 14:23:25 +00:00
|
|
|
if starts_with '/' "$argv"
|
|
|
|
source "$argv.fish"
|
|
|
|
return 0
|
|
|
|
end
|
2023-01-04 01:28:50 +00:00
|
|
|
source $self_directory/"$argv.fish"
|
|
|
|
end
|