27 lines
866 B
Fish
Executable File
27 lines
866 B
Fish
Executable File
#!/usr/bin/env fish
|
|
|
|
# parent prints the parent script's filename
|
|
function parent
|
|
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])
|
|
# Clean up the parent a lil bit
|
|
set -f parent (realpath (string replace '~' "$HOME" $parent))
|
|
set -f parent_parts (string split '/' $parent)
|
|
set -f parent (string join '/' $parent_parts[-1])
|
|
|
|
# remove .fish suffix
|
|
set -f parent (string replace '.fish' '' $parent)
|
|
|
|
echo $parent
|
|
end |