Thursday, September 11, 2008

Jump to Percent of File

Sometimes you don't know the exact line you want to go to in a file, but you can infer an approximate percentage. I was browsing a 200 meg logfile with Vim yesterday and guestimated the area of interest was about 10% back from where I was at (85%). You can easily jump to a desired percentage in a file by typing in the percentage followed by a percent symbol.

Jump to 50% of the file:

50%

Easy to remember to say the least ;-)

Wednesday, September 10, 2008

Scrollbind

You can :set scrollbind in any windows in Vim that you would like to scroll together.

Thanks to Chris for the tip.

Monday, September 8, 2008

Determining Linux Version

Linux distributions don't tend to standardize where they store information about what release is installed. Going further, there's not even a standard way to detect what distribution is installed. If a system is running a popular distro, this information can usually be found in one of the following files:


Debian /etc/debian_release, /etc/debian_version,
Fedora /etc/fedora-release
Gentoo /etc/gentoo-release
Mandrake /etc/mandrake-release
Novell SUSE /etc/SUSE-release
Red Hat /etc/redhat-release, /etc/redhat_version
Slackware /etc/slackware-release, /etc/slackware-version
Solaris/Sparc /etc/release
Sun JDS /etc/sun-release
Ubuntu /etc/lsb-release
UnitedLinux /etc/UnitedLinux-release
Yellow dog /etc/yellowdog-release


You can find more information on this problem as well as a shell script to assist with OS detection here. An even larger master list can be found here.

Ubuntu Audio Sharing

For a good while, audio sharing issues plauged my Ubuntu workstation. Whenever I'd hit a website that used Flash 9, none of my other audio applications would be able to access the audio device until my Gnome session was restarted. Googl'ing around for Ubuntu and Flash, I stumbled onto this package, which I'm happy to say solved the issue.

Ubuntu libflashsupport.

Obviously, you can install it quite easily with apt.

sudo apt-get install libflashsupport

Hope this helps somebody.

Friday, September 5, 2008

Repeat Last Command Line

To repeat the last command-line given in ex mode, you can simply enter a count followed by "@:".

Swap Characters

To swap two adjacent characters in Vim you can issue an "xp" command in normal mode.

Gnome Terminal Tips

I often use the profiles feature in gnome terminal to organize all my remote shell accounts. Inside of gnome terminal, you can go to Edit->Profiles to manage your profiles. From there, you can either edit an existing profile or create a new one. Either action will take you to the "Editing Profile" window. Once inside, click on "Title and Command" tab and check the box that says "Run a custom command instead of my shell". You can put your ssh login info inside of the "Custom command" box. An example would be:

ssh -i /home/username/.ssh/id_rsa.1 -p 7822 myuser@myhost.com

That would invoke an ssh session using port 7822 and the identity file stored in your .ssh directory. It's particularly useful to setup sessions with shared keys so you can just go File->Open Terminal and point to the desired session. If you have certain ssh session you use a lot, it might be worth adding a launcher to your panel and specifying the desired profile like so:

gnome-terminal --window-with-profile SomeProfile

It's also worth noting that gnome terminal allows you to color code your saved profiles. I find that this helps prevent stupid mistakes caused by thinking your logged into a different session than you actually are.

Since I use gnome terminal to store many remote login sessions, I sometimes need to retrieve this information whilst remotely logged into my workstation. An example would be when I ssh to my work PC from home over a VPN connection. Gnome terminal stores all of it's saved profile information in the following location.

/home/$username/.gconf/apps/gnome-terminal/profiles/$profilename/%gconf.xml

In this case, $username and $profilename would represent your username and desired gnome profile name respectively. Inside of the %gconf.xml file, there's a section for custom command that looks like this.

<entry name="custom_command" mtime="1193759925" type="string">
    <stringvalue>ssh -p 7822 username@somehost.org</stringvalue>
</entry>

From there, you should be able to extract whatever info is desired.

Bonus tip: you can open a new terminal window whilst inside an active gnome terminal session by doing ctrl-shift-N.