Category Archives: Automation / Scripting

xbindkeys configuration


  1. mouse side button 8 sends Enter
  2. mouse side button 9 sends alt+left
  3. tilde sends ctrl+w



sudo apt-get install xautomation
sudo apt-get install x11-utils
sudo apt-get install xdotool

To find the keycodes run xev or xbindkeys -k:

xbindkeys - k

Here is a sample script:

#send alt+left on side button 9
"xte 'keydown Alt_L' 'key Left' 'keyup Alt_L'"

#send Enter on side button 8
"xte 'key Return'"

#Using keycodes
"xte 'keydown Control_L' 'key w' 'keyup Control_L'"
    grave + release



Google docs – send a doc monthly via email

Here is a small script you can attach to a document on Google docs.

Whenever run, it will attach the file and send it to you via e-mail

function monthlyBackup() {
  var formattedMonth = Utilities.formatDate(new Date(), "GMT", "MM");
  var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd' 'HH:mm:ss"); var name = SpreadsheetApp.getActiveSpreadsheet().getName() + " backup " + formattedDate;
  var ssID = SpreadsheetApp.getActiveSpreadsheet().getId(); var sheetName = SpreadsheetApp.getActiveSpreadsheet().getName(); //var email = Session.getUser().getEmail(); var email = "XXX@XXX.XXX";
  var subject = SpreadsheetApp.getActiveSpreadsheet().getName() + " backup at " + formattedDate;
  var body = "This is automated backup from google docs :)";
  var requestData = { "method": "GET", "headers":{"Authorization":"Bearer "+ScriptApp.getOAuthToken()} };
  var url = ""+ ssID + "/export?format=ods&id="+ssID;
  var result = UrlFetchApp.fetch(url , requestData);
  var contents = result.getContent();
  var attachedFilename = sheetName + " " + formattedMonth + ".ods";
  MailApp.sendEmail(email, subject ,body, {attachments:[{fileName:attachedFilename, content:contents, mimeType:"application//x-vnd.oasis.opendocument.spreadsheet"}]}); }


For more MIME types read this article:

If you want to add a menu item you can also the following code:


function onOpen() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var menuEntries = [ {name: "Send Email", functionName: "monthlyBackup"}];
 ss.addMenu("Scripts", menuEntries);



Bash history expansion 🏅

The general syntax is:


Command segment defines which command to look for in history. It can be a modifier like !! (last command), !-1, !-2, !-3 … (last, previous to last etc) or a specific keyword like !cat (search for most recent cat).

Parameter segment defines which part of the command to use. ^ is first parameter, $ is last parameter, * are all the parameters, 0 the command and 1,2,3… are the parameters. You can define a range eg 2-4 (parameters 2 to 4)

Besides that, you can also use ^x^y^ to replace x with y. There are some more advanced ways to search. Take a look at the references at the end of this page.

You can also use history n to review the last n commands with their ids. If you know an id, you can use it at command segment,

All results are shown as if the command was executed immediately after touch a b c d e (not one after another)

Assume that you have typed in this order:

  1. ls -a -r
  2. date
  3. touch a b c d e
!! last command (all words) touch a b c d e
!* last command, all arguments a b c d e
!^ last command, second argument a
!$ last command, last argument e
!:0 first word touch
!:1 second word (first argument) a
!:2-4 range of words b c d
 ^touch^ls find touch and replace it with ls  ls a b c e d
!-1 last command touch a b c d e
!-2 previous to last command date
!-2:0 first keyword of previous to last command date
!ls:* search for command ls,
all arguments of ls
-a -r
!ls:^ search for command ls,
first argument of ls
!ls:$ search for command ls,
last argument of ls
!ls search for command starting from ls ls -a -r
!? b search for command containing b touch a b c d e
!!:gs/a/p/ last command, replace a with b touch p b c d e


Book recommendation:

UNIX Shells by Example, Ellie Quigley