Use aliases in the Alt-F2 dialog

Solution 1:

Not really, no. I am not sure about the details but I imagine that the Alt+F2 is simply passing the commands you run to a non-interactive, non-login shell. This type of shell will not have access to aliases, as explained in man bash:

   When bash is started non-interactively, to  run  a  shell  script,  for
   example, it looks for the variable BASH_ENV in the environment, expands
   its value if it appears there, and uses the expanded value as the  name
   of  a  file to read and execute.  Bash behaves as if the following com‐
   mand were executed:
          if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
   but the value of the PATH variable is not used to search for  the  file
   name.

So, you might think that you can just set BASH_ENV to point to a file containing alias definitions. Unfortunately, aliases are not available to non-interactive shells. Again from man bash:

   Aliases are not expanded when the shell is not interactive, unless  the
   expand_aliases  shell option is set using shopt (see the description of
   shopt under SHELL BUILTIN COMMANDS below).

You might think that you could add shopt -s expand_aliases to the file defined by $BASH_ENV but that won't work because that file will be read but in a different shell.

I know this is confusing. Bottom line, you can't make aliases available to the Alt+F2 dialog.


A workaround

So, since you can't do this with aliases, what you can do is do it with scripts:

sudo -H gedit /usr/bin/geditm

That will bring up a new gedit window, add these lines to it and save the file:

#!/bin/bash
gedit --display=D1

Make the script executable:

sudo chmod a+x /usr/bin/geditm

Now, you can hit Alt+F2, write geditm and that script will be launched which in turn launches gedit with the desired options.

Solution 2:

Note: after rereading your question and thinking about it longer, I think the answer by terdon is probably the one you want, not this one; this one is too general, and takes more typing.

If I understand correctly, it seems like you might want to append --display=D1 to any program you run from Alt-F2; is this correct? After some discussion, probably not, so be sure to see "EDIT2" along with this for a different take.

If so, it seems like you could create a simple script that would live in some folder in your path, like ~/bin, that would simply say

#!/bin/bash
$1 --display=D1

If you name the script "display", then from Alt-F2 you could run display gedit, and it should append "--display=D1".

EDIT: I guess you will need to make it executable, using chmod +x display

I can't really easily test that, but it should work (assuming this is what you want to do.

EDIT2: It seems I didn't fully understand your question, but I think you can still use a similar method. Instead of specifying the flag, you can use substitutions for both the command and the flags. I guess you could simply say

$*

instead of

$1 --display=D1

Then the Alt-F2 command would be "display xxxx yyyy ..."