Panduan Linux

Membuat Shortcut Keyboard untuk Menjalankan Bash Script

Yo, peeps! Pernah nggak sih kalian capek ngetik perintah yang sama terus-terusan di terminal? Atau mungkin pengen ngejalanin script bash dengan sekali pencet tombol? Nah, shortcut keyboard bisa jadi solusinye! Dengan ngeset shortcut, bisa deh ngejalanin script bash tanpa ngetik command panjang-panjang. Bikin hidup lebih gampang kapok!

Step 1: Bikin Bash Script Dulu

Pertama-tama, pastiin dulu punya file bash script yang pengen dijalanin. Misal, kita bikin file hello.sh yang isinya:

#!/bin/bash
echo "Hello, World!"

Jangan lupa bikin filenya bisa dijalanin pake chmod:

chmod +x hello.sh

Step 2: Bikin Alias di .bashrc atau .bash_aliases

Alias tuh kayak shortcut buat command. Buka file .bashrc atau .bash_aliases (kalo ada) di home direktori.

nano ~/.bashrc

Terus, tambahin alias buat ngejalanin scriptnya. Misal:

alias hello="~/path/to/hello.sh"

Jangan lupa source file .bashrc biar aliasnya aktif:

source ~/.bashrc

Sekarang, bisa panggil script pake hello aja di terminal.

Step 3: Bikin Shortcut Keyboard dengan xbindkeys

Nah, kalo pengen ngejalanin script pake shortcut keyboard, kita bisa pake xbindkeys. Pertama, install dulu xbindkeys sama xdotool:

sudo apt install xbindkeys xdotool

Terus, bikin config file buat xbindkeys:

xbindkeys --defaults > ~/.xbindkeysrc

Buka file .xbindkeysrc:

nano ~/.xbindkeysrc

Terus, tambahin shortcut. Misal, pake Ctrl + Alt + H buat ngejalanin hello.sh:

"xdotool key --clearmodifiers Escape && xdotool key --clearmodifiers Return && xdotool type 'hello' && xdotool key Return"
  Control+Mod2 + h

Keterangan:

Simpen file, dan restart xbindkeys:

pkill xbindkeys
xbindkeys

Sekarang, coba pencet Ctrl + Alt + H di keyboard. Kalo bener, hello.sh bakal jalan dan nampilin “Hello, World!” di terminal.

Step 4: Biar Shortcutnya Auto Start

Biar shortcutnya jalan tiap kali komputer nyala, tambahin xbindkeys ke startup applications. Caranya:

  1. Buka “Startup Applications” (biasanya ada di menu system).
  2. Klik “Add”.
  3. Isi:
    • Name: xbindkeys
    • Command: xbindkeys
    • Comment: Keyboard Shortcuts
  4. Klik “Save”.

Sekarang, setiap kali login, xbindkeys bakal jalan otomatis.

#Bash Script #Linux