0

I am developing a simple cli-application for timetracking. The idea is to have fish-aliases source r-scripts to create timestamps in a timetable. Like so:

alias checkin='rscript (echo $PWD/checkin.R)'

However writing it like this only allows me to call the alias if I am standing in the correct directory. Is there a way for me to hardcode the current path, so I can call it from any directory?

1
  • I'm struggling a bit to understand the flow. Does that rscript (echo $PWD/checkin.R) work from any directory when not in an alias? Commented Nov 13, 2022 at 16:14

1 Answer 1

2

The single quotes are the problem. They prevent variable expansion.

If you want to use the PWD when you define the alias, use double quotes:

cd /the/wanted/directory
alias checkin "rscript $PWD/checkin.R"

(the = is optional)

See how it is defined: type checkin

Then funcsave checkin to save the function (which the alias creates) permanently with the correct path.

2
  • Thank you. This helped me solve my problem!
    – s_dav
    Commented Nov 18, 2022 at 14:51
  • Note: This will be broken if the current directory contains spaces or any special characters - to alias they'll look like separate arguments. It's probably much nicer to define an actual function and use --inherit-variable to inherit the value.
    – faho
    Commented Nov 23, 2022 at 8:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .