Ubuntu – Create a clickable desktop shortcut for an alias

aliasunity

For example, let's say I have defined an alias under my .bash_aliases,

alias gotoheaven="xdg-open /path/to/heaven"

now I wish to create a clickable icon for it on the desktop.
[I know make link to create folder shortcut, but this I am asking is just for an example so that I can extend it to create any other type of shortcuts].
Edited:
The shortcut is bind to the alias. Something like open Terminal and run gotoheaven. In this way I do not have to re-write alias into the Exec entry.

Best Answer

To be exact there is a method, i.e. running the alias in an interactive shell;

I.e., create a desktop file with the following Exec= line:

Exec=bash -c 'exec bash -i <<<"gotoheaven"'
  • bash -c '[...]': starts a non-interactive shell (this is required to take advantage of the <<< redirection) and runs [...] in it;
  • exec bash -i <<<"gotoheaven": replaces the non-interactive shell with an interactive shell and redirects gotoheaven to the interactive shell's STDIN, which sources ~/.bashrc and runs the alias.

However since this requires more or less the same effort of copy-pasting the command from the alias into the new desktop file but runs an additional shell, I suggest you to just go for copy-pasting the command from the alias into the new desktop file as outlined in one of the answers to this question.

You seem to be stuck on the fact that the shortcut must run the alias and not an identical command, which just doesn't make sense unless you need to run the command in the environment set by ~/.bashrc (which doesn't seem to be the case). Just create a desktop file that runs the same command.

Related Question