Saturday, May 17, 2014

Case Insensitive Autocompletion in Bash

Today I learnt how to get case insensitive autocompletion in Bash.

Just put the following line in ~/.inputrc:

 set completion-ignore-case On  

That's it. To learn more about what is really going on, the bash and readline manual pages should be read.


Sunday, May 4, 2014

Using Upstart in Ubuntu 12.04 to set screen brightness during boot in Asus Eee PC

First I wrote a small script in /usr/local/bin to set the brightness to the lowest possible value (the lowest value is plenty bright for my eyes):

 $ cat /usr/local/bin/set-screen-brightness.sh   
 #!/bin/bash  
 echo $1 > /sys/class/backlight/acpi_video0/brightness  

Then I made the script executable. Next I wrote the following upstart script:

 $ cat /etc/init/my-brightness.conf   
 description "Set laptop screen to lowest brightness level"  
 start on runlevel [2]  
 script  
   exec /usr/local/bin/set-screen-brightness.sh 0  
 end script  

(My default runlevel (as indicated by running the runlevel command) is 2)

At the next boot, my screen's brightness is automatically set to the provided 0 value.

If I wanted to start the 'my-brightness' upstart service anytime, I would simply use the following command:

 $ sudo service my-brightness start  

Hiding the Unity2d launcher when not in use (Ubuntu 12.04)

The command to hide the Unity2d launcher when not in use is:

 gsettings set com.canonical.Unity2d.Launcher hide-mode 1  

Wednesday, April 30, 2014

Connecting to wifi access point from the terminal

The following process has worked for me. I simply followed the procedure mentioned in arch linux wiki with a small tip from one of their forum post. So, a big thanks to the Arch community.

First of all, I am assuming all the wireless drivers are installed and loaded properly. I used the commands: iw, ip, wpa_supplicant for the process. NetworkManager was not used.

 $ iw dev  
   phy#0  
     Interface wlan0  
     ifindex 3  
     type managed  

This gives me the name of the wireless interface: wlan0

 $ ip link show  
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN   
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
 2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  
 3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  

That means my wireless link wlan0 was not UP (otherwise the word UP would be there within <>)

 $ sudo ip link set wlan0 up  
 $ ip link show  
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN  
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
 2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  
 3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  

Now, the wlan0 is UP. So, now it is time to find out what access points are available.

 $ sudo iw dev wlan0 scan | grep SSID  
     SSID: TP-LINK_POCKET_3020_C50F1E  
     SSID: Ramananda  

Ok. I want to connect to the first one. But before that I need to create a wpa_supplicant.conf file with the SSID and Password for the Access Point to which I want to connect.

 $ wpa_passphrase TP-LINK_POCKET_3020_C50F1E xxxxxxxx > wpa_supplicant.conf  

Now that the wpa_supplicant.conf file is generated, I can attempt to connect to the access point.

 $ sudo wpa_supplicant -iwlan0 -c wpa_supplicant.conf  
 ioctl[SIOCSIWENCODEEXT]: Invalid argument  
 ioctl[SIOCSIWENCODEEXT]: Invalid argument  
 Trying to associate with xx:xx:xx:xx:xx:xx (SSID='TP-LINK_POCKET_3020_C50F1E' freq=2462 MHz)  
 Associated with xx:xx:xx:xx:xx:xx  
 WPA: Key negotiation completed with xx:xx:xx:xx:xx:xx [PTK=CCMP GTK=CCMP]  
 CTRL-EVENT-CONNECTED - Connection to xx:xx:xx:xx:xx:xx completed (auth) [id=0 id_str=]  

I don't know about the ioctl lines, but now I am connected to the wireless access point. Now what I need to do is to use dhclient3 or dhcpcd to get an ip address from my access point (which is also configured as a dhcp server)

 $ sudo dhclient3 wlan0  

Done. Now I can successfully ping google :-)

Dear Inconsolata, I want to use you properly

I never got why inconsolata font is considered good for coding and things like that... until today.

I learnt that if I set autohint=true for the Inconsolata font in Linux (I am currently on Ubuntu 14.04), it actually looks great!

So, after reading some portions of the fonts.conf(5) manual page, I added the following stanza to my .config/fontconfig/fonts.conf file so that autohinting will be selectively turned on only for the Inconsolata font (others fonts tend to look horrible if autohinting is turned on as far as I am concerned):

 <match target="pattern">
     <test name="family">
         <string>Inconsolata</string>
     </test>
     <edit mode="assign" name="autohint">
         <bool>true</bool>
     </edit>
 </match>