Monday, August 4, 2014

Using xdg-mime to set default programs to open certain filetypes in Linux

Recently I had a need to set xpdf as the default program for opening pdf files instead of evince. I decided to use the command line to achieve this. Turns out that I can do this using xdg-mime.

To know what is the filetype (in the mime 'language') of pdf files:

 $ xdg-mime query filetype Programming.pdf  

Once I know the mime type of pdf files, I can see the default program currently used to open pdf files:

 $ xdg-mime query default application/pdf  

So, now I know that evince is being used as the default pdf file opener, and that there is a desktop file by the name of evince.desktop. The location of this file can easily be found using programs like 'locate':

 $ locate /evince.desktop   

Now I know where such desktop files are kept on my system. After installing xpdf, xpdf.desktop also turned up there (if not it is easy to create such a desktop file). So now I can make xpdf as the default program for opening pdf files using the following:

 $ xdg-mime default xpdf.desktop application/pdf   

That's it. Now if I try to click on a pdf file, xpdf is used to open it.

Thursday, July 31, 2014

Making git know about my http and https proxy server

Following is the general syntax of the commands that will set the http and https proxy servers for git:

 git config --global http.proxy http://proxyuser:proxypassword@proxyserver:proxyport  
 git config --global https.proxy http://proxyuser:proxypassword@proxyserver:proxyport  

For example, if I want to set the http and https proxy servers to, then I would use the following command (assuming my proxy server requires no authentication):

 git config --global http.proxy
 git config --global https.proxy

Sunday, June 15, 2014

Go away Desktop icons... again!

I want my desktop to be clean. That means no icons. Recently I have been trying various window managers, and finally I settled down to i3 for the past few weeks. I love it.

Today, I just wanted to log into Unity just for change, and found things have changed since I last logged into it. That's strange since I never did this and nobody is using my PC. I was seeing desktop icons!

I wanted to get rid of those. So I used gsettings to find out 'who' was responsible for this. It turned out to be some program called nemo. The following command:

 ➜ ~ gsettings list-recursively | grep -i desktop | less  

turned up, among other things, this:

 org.nemo.preferences desktop-is-home-dir true  

So, to set things right, I had to do this:

 ➜ ~ gsettings set org.nemo.desktop show-desktop-icons false  

Now, things are right again.

Now that I think about this, I did play with Cinnamon recently, didn't quite like it, and then forgot all about it. Maybe, this was a result of that adventure... nemo being a part of Cinnamon...

(Oh, in case anyone was wondering, those command prompts are due to oh-my-zsh that I am using nowadays)

Wednesday, June 4, 2014

Getting audio volume go beyond 100% in Ubuntu Gnome

In some videos I find the audio volume to be too low, even after the I turn the volume up to 100%. However, from gnome's sound control, I can see that I can use the mouse to make the volume go beyond 100% so that the audio becomes louder.

So, I was looking for a command line that would do that for me, so that I can assign that to a keyboard shortcut so that every time I needed louder sound, I would not have to use my mouse to reach out for the gnome sound control.

I turned out that the pactl command (from pulseaudio-utils package in Ubuntu) can be used for this purpose.

To make the volume go up by 10%, the command would be:

 pactl set-sink-volume 0 +10%  

And to make the volume go down by the same amount, the command would be:

 pactl set-sink-volume 0 -- -10%  

(The '--' in the command above is necessary otherwise it is interpreted as a command line option and I get an error. The '--' basically stops the shell from option parsing from that point onward)

This command allows me go beyond 100%

Now I have assigned this command to a shortcut key in Gnome and my problem is solved :-)

BTW, if there are more audio devices, the index may need to be changed from 0 (I have only one, so the index is 0 in my case). More details are available in the 'pactl' and 'pacmd' manual pages.

Sunday, May 25, 2014

Solution for: Mouse cursor disappears when starting i3 with gnome-settings-daemon (in Arch Linux)

In my arch installation, whenever I start the i3 (or awesome) window manager as a gnome-session (which starts gnome-settings-daemon), the mouse cursor disappears. It is there, since I can click on things, but not visible. It is possible that the same problem exists when other window managers are started (other than gnome shell), but I have not tested with other window managers.

The solution turns out to be to run the following command:

 gsettings set org.gnome.settings-daemon.plugins.cursor active false  

That makes the mouse cursor visible again.

Sunday, May 18, 2014

Font settings I used in my Arch Linux install (on USB Pendrive)

I have the following content in my ~/.config/fontconfig/fonts.conf:

 <?xml version='1.0'?>  
 <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>  
   <match target="font">  
     <edit mode="assign" name="autohint">  
   <match target="font">  
     <edit mode="assign" name="rgba">  
   <match target="font">  
     <edit mode="assign" name="hinting">  
   <match target="font">  
     <edit mode="assign" name="hintstyle">  
   <match target="font">  
     <edit mode="assign" name="antialias">  

Also, from AUR, I have installed the package 'ttf-win7-fonts-autodownload'.

Further, I have installed 'ttf-ubuntu-font-family'.

In Firefox I have installed the "Theme Font & Size Changer" add-on.

IIRC, that's all I did to get great (at least to my eyes) fonts in my Arch installation.

By the way, this Arch installation is on a USB pendrive, allowing me to carry my Linux around all the time. Apna Linux Pehen Ke Chalo :-)

Using gsettings to set font preferences in my shiny Ubuntu Gnome 14.04 Desktop

Instead of using gnome-tweak-tool, this time I have used the command line utility 'gsettings' to set my font preferences in Gnome (Ubuntu Gnome - 14.04). After invoking some 'gsettings set ...' commands, I have the following:

 ubuntu-gnome@ubuntu-gnome:~$ gsettings list-recursively org.gnome.settings-daemon.plugins.xsettings   
 org.gnome.settings-daemon.plugins.xsettings disabled-gtk-modules @as []  
 org.gnome.settings-daemon.plugins.xsettings priority 0  
 org.gnome.settings-daemon.plugins.xsettings hinting 'full'  
 org.gnome.settings-daemon.plugins.xsettings overrides {'Gtk/ShellShowsAppMenu': <0>}  
 org.gnome.settings-daemon.plugins.xsettings rgba-order 'rgb'  
 org.gnome.settings-daemon.plugins.xsettings antialiasing 'rgba'  
 org.gnome.settings-daemon.plugins.xsettings active true  
 org.gnome.settings-daemon.plugins.xsettings enabled-gtk-modules @as []  

(Note the keys 'hinting', 'rgba-order' and 'antialiasing')

To know which values are valid for any key, there is the 'range' command. For example, to know what are the possible values I can use for the 'antialiasing' key, I can use the following command:

 ubuntu-gnome@ubuntu-gnome:~$ gsettings range org.gnome.settings-daemon.plugins.xsettings antialiasing  

That means I can use one of those three enum values for the 'antialiasing' key.

Saturday, May 17, 2014

Prevent desktop icons to show up in Unity Desktop (Ubuntu 14.04)

Just type in the following command at a shell prompt:

 $ gsettings set org.gnome.desktop.background show-desktop-icons false  

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/   
 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]  
   exec /usr/local/bin/ 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  
     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">
     <edit mode="assign" name="autohint">

Monday, February 10, 2014

Getting the correct pre-requisites for building gcc

Today I had to build a gcc cross compiler for my OS related experiments (I was building the bare bone OS as described in For some reason, gcc would not build. Turned out the versions of mpc, mpfr and gmp that I downloaded were likely not compatible, and were causing problems.

After some searching on the net I found that inside gcc source tree, there is a folder called contrib which contains a script called download_prerequisites. So, all I needed to do was to get into gcc source folder and execute:

$ ./contrib/download_prerequisites.

This downloaded the correct versions of the prerequisites and I was then able to successfully build the i586-elf target gcc cross compiler.

Thursday, January 2, 2014

An excellent source of some nice tutorials

Today, I was looking for some nice tutorial videos on intel assmbly language, and found this:

Very informative.

I think I am going to frequently visit this site for their nice tutorials on some interesting topics which I find interesting.