Score:4

Set parameters for Ubuntu's alias

cn flag

I have an example command as follows:

g++ main.cpp -o main -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -I/usr/local/include/opencv4

Running the entire above command will create file main based on the second argument main after the parameter -o. I have reset it in file .zshrc as follows:

alias ocv='f(){ g++ "$@" -o built_$@ -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -I/usr/local/include/opencv4; unset -f f; }; f'

Now run the above command as follows:

ocv main.cpp

It will create a file called built_main.cpp. But I want it to generate the file main by removing the extension .cpp. How to do it?

D. Ben Knoble avatar
lk flag
Why an alias that invokes a self-deleting function instead of a full function? You could even autoload it in zsh, were it a function, in addition to having more “room” for more complex tasks. Though, for this particular case I would actually recommend some kind of build tool, such as make.
Score:6
pl flag

For zsh you should use modifier :r on $@, see e.g. this.

So it would be

alias ocv='f(){ g++ "$@" -o built_$@:r -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -I/usr/local/include/opencv4; unset -f f; }; f'
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.