Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

13 May 2014

576. Shortening the bash prompt in debian

This is yet another post in which I'm (almost) simply reposting a solution that someone else has already posted online.

Let's say that my contribution is to put it in context of debian.

Either way, here's the problem that needed solving: the debian prompt by default lists all directories, which sometimes means that the prompt itself breaks across two lines.

Luckily, it's not difficult to chop the prompt down to a more manageable, yet still informative, length. The solution is here (we do like a descriptive URL):

That particular solution also allows you to change the permissible length of the path that will be shown -- change the 50 in the argument to droppath to set the number of chars.

Edit your ~/.bashrc and add the bits in red:
# drops first portion of a path $1 if length is greater than $2 function __droppath { if [[ ${#1} -gt $2 ]]; then p=$1 while [ ${#p} -gt $2 ]; do p="/"$(echo "$p"|cut -d"/" -f3-) done echo "..."$p else echo $1 fi } if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]$(_droppath "\w" 50)\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h: $(__droppath "\w" 50)\$ ' fi

and here's an example using a length of 25 chars (which is a bit short).

me@niobium: /usr/local/lib/python2.7/site-packages$\

me@niobium: .../python2.7/site-packages$

You can always use pwd to figure out what the full path is if necessary:
me@niobium: .../python2.7/site-packages$ pwd

08 January 2012

41. Chinese character and input support on debian testing

Update: You should also install support for gtk and gtk3:
sudo apt-get install ibus-gtk3 ibus-gtk
in order to be able to use it with e.g. thunderbird.

Original post:
Here's how to set up Chinese (simplified) support in Gnome 3 /gnome-shell and the terminal (bash).

First install the fonts:
sudo apt-get install fonts-arphic-*

Next. add Chinese via locales:
sudo dpkg-reconfigure locales


(For traditional characters choose zh_HK, zh_SG or zh_TW)

As default language English is probably a good idea
In my case it's en_AU.UTF-8

Edit ~/.bashrc and add the following lines:

source .bashrc

Install ibus:
sudo apt-get install ibus-pinyin 
This pulls another 18 packages with it

Start ibus-daemon in terminal
An icon in the notification tray still appear
Right-click, choose Preferences (P)
Click on the second tab (input methods)
Select an input method -> Chinese -> Pinyin

You should now be able to choose between regular (latin) input and Chinese characters using Ctrl+Space.

To make ibus-daemon start with gnome, run
and add

And you're more or less done.

Sogou is a popular pinyin database on the Windows platform -- but afaik it's not available for Linux. On Linux, it seems that the ibus-pinyin-db-open-phrase database is the default ibus database used to guess what characters you intend to type, but you can also install and select either ibus-googlepinyin or ibus-pinyin-db-android. After installation you need to select the database by going to preferences in the ibus daemon and selecting it as input method. Not being Chinese I can't tell whether sogou, google pinyin and android pinyin are comparable.

Sogou does however work with Google Chrome/Chromium on linux -- go to Preferences/Extensions -- Get More Extensions, and install the Sogou Cloud Pinyin Extension for Chrome.

28 July 2011

10. Combining MS data into a matrix

The following script takes a series of files with comma-delimited data named 0v.csv, 10v.csv etc., extracts everything in column 4 (in my case it contains relative abundance values from MS) from row 7 to the bottom, and stores those columns in files called 0.dat, 10.dat etc.

The second column (in my case it contains m/z values) is extracted from one of the csv files, and stored in mz.x.

Next, all the .dat files are pasted together, with the columns side by side, and the mz.x data added as the first column.

The data is rotated using the rotate script I've published earlier.

A file with cone-voltage values, cv.xy, has already been prepared by hand (single column), and is pasted together with the m/z data.
for e in 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 220 240 260 280 300
tail -n +8 $e\v.csv | sed 's/\,/\t/g'| gawk '{print $4}' > $e.dat

#get m/z
tail -n +8  0v.csv | sed 's/\,/\t/g'| gawk '{print $2}' > mz.x

paste  0.dat 10.dat 20.dat 30.dat 40.dat 50.dat 60.dat 70.dat 80.dat 90.dat 100.dat 110.dat 120.dat 130.dat 140.dat 150.dat 160.dat 170.dat 180.dat 190.dat 200.dat 220.dat 240.dat 260.dat 280.dat 300.dat > all.dat
paste mz.x all.dat > $1dat
rotate $1.dat > $1\rot.dat
paste cv.xy $1\rot.dat > $1\tot.dat