Search code examples
fishesp-idf

calling source from within a function


I'm currently moving from zsh to fish. Most of my aliases etc are pretty easy to port, but I'm running into problems with the following one:

alias idf.py='unalias idf.py; source $IDF_PATH/export.sh; idf.py'

I know in fish aliases are just syntactic sugar for functions so I started writing the following function:

function "idf.py"
  source $IDF_PATH/export.fish
  functions --erase idf.py
  idf.py $argv
end

the export.fish script is from the esp-idf and starts complaining about needing to be sourced. After that the function gets removed correctly but idf.py can not be found:

his script should be sourced, not executed:
realpath: /home/robert/Programs/esp-idf/export.fish/..: Not a directory
.
fish: Unknown command: idf.py
fish: 
  idf.py $argv
  ^
in function 'idf.py'

Do you have any idea how I can source to the global scope from within this function?


Solution

  • Just going on the commit history of the project you linked to -- The ESP-IDF script you linked is the latest version, but the error you are receiving was from a bug in an earlier version of the script that has since been fixed.

    The script attempts to detect whether it is being called with the source command by testing status current-command, but since you are calling it from within the function idf.py, that's the name returned, rather than source.

    It was a bug, and it was fixed about two years ago by simply removing the source check.

    Upgrading to the latest ESP-IDF release should take care of it.