6

Is it possible to use an alias within a custom shortcut?

For example, suppose I have the alias

alias cal="google-chrome --new-window calendar.google.com"

Can I create a custom shortcut that binds Ctrl+Alt+C to cal?

I have tried but it doesn't seem to work.

6

Yes, you can. You just need to ask the command for an interactive shell.

Let's say your alias is:

alias myalias='some cool command here'

Your shortcut command must be:

bash -i -c "myalias"

screenshot of setting up alias in keyboard settings

5

No, the commands run by keyboard bindings are not parsed via a shell. Your best bet is to create a directory bin in your homedir (mkdir -p ~/bin). Write a script named cal that runs your command, save it in ~/bin and make it executable.

$ mkdir -p ~/bin
$ cat > ~/bin/cal << 'EOF'
#!/bin/sh
exec google-chrome --new-window calendar.google.com
EOF
$ chmod +x ~/bin/cal

If you didn't have a bin directory in your homedir already, you need to log out and back in again for it to be added to your PATH. Once that is done, binding a keyboard binding to run "cal" should do what you want.

-1

a quick alternative, in case it helps anyone in the future

to add a "Save Image As.." keyboard shortcut to Chrome as Shift-Ctrl-S

command: bash -c "xdotool click 3 && sleep 0.5 && xdotool key v;"

also, if you're organized enough to keep a separate file with your shortcuts & then sourcing it at the end of ~/.bashrc for example, the following works & can comes in handy ;)

command: bash -c ". /tmp/keyboardShortcutsFcns && tefAliasFcn"

content of the "/tmp/keyboardShortcutsFcns" file from the above example:

# test fcn to be called ( maybe ? ) from a keyboard shortcut tefAliasFcn(){ notify-send "tef alias function called succesfully !"; }

1
  • This doesn't seem to answer the question. – wjandrea Oct 27 '18 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.