2009年11月24日 星期二

[2009-11-24-2] Build Android platform for Qualcomm chipsets

想要一窺Qualcomm's AOSP(The Android Open Source Project),可以連上[1]download以及build it,步驟如下:

Step1:
(如果沒有安裝repo,可以參考這裡的step1、2)
選好想要的branch及manifest(這裡brance選carrot.cupcake, manifest選M7201JSDCBALYA638501.xml)就可以準備下載source code
$ mkdir QAEP
$ cd QAEP
$ repo init -u git://codeaurora.org/platform/manifest.git -b carrot.cupcake -m M7201JSDCBALYA638501.xml 
$ repo sync

Step2:
設定環境變數, 選定1(device), 1(release), msm7201a_surf(target), eng(default mode), 開始make囉!!
$ source build/envsetup.sh
$ choosecombo 1 1 msm7201a_surf eng
$ make -j4

Step3:
build出來的img會在out/target/product/msm7201a_surf中, 包括了boot.img, systme.img等。再使用fastboot, 燒img到device(記得要先接上device)
$ sudo out/host/linux-x86/bin/fastboot flash boot out/target/product/msm7201a_surf/boot.img
$ sudo out/host/linux-x86/bin/fastboot flash system out/target/product/msm7201a_surf/system.img


Step4:
使用adb 確認device,

(to be continue)


[參考]
[1] MSM/QSD Android Enablement Project
[2] 工程模式與FASTBOOT - Android Dev Phone 1
[3] Developing on a Device
[4] Make UDC & Android ADB Gadget driver work
[5] 編譯android原始碼到模擬器上執行

2009年11月17日 星期二

[2009-11-17-2] Android usb driver for Windows

Android usb driver 其實是來自Android SDK, 不過SDK記得選Windows platform囉!再來就是解壓後,直接執行"SDK Setup.exe", 記得在Settings中勾選"Force https://...", 再如下圖不要勾選"Display updates only"就可以看到"Usb Driver package..", 再"Install Selected" --> "Accept All" --> "Install Accepted"即可以下載,看到"usb_driver" 資料匣囉!!



接下來,把device接上PC,再安裝剛抓下來的usb_driver就可以完成,如下圖找到ADB Interface

2009年11月9日 星期一

[2009-11-09-1] Android 的環境設定檔 - envsetup.sh

在Android要找關鍵字, build module 等等,確實有點不方便,所以就自己寫一個.sh file 或是用Android貼心的envsetup.sh。

$ cd ~/cupcake/buile
$ source envsetup.sh
$ help  #試一下help 吧!
$ croot #回到cupcake
$ cgrep 'main' #在c/c++ 找 main字串
$ jgrep 'main' #在jave 找 main字串
$ resgrep 'main' #在res/*.xml 找main字串
$ m lottery_ray #同 make lottery_ray, 記得touch lottery.c, 就可以rebuild了
還有很多好用的指令就 vim envsetup.sh吧!

2009年11月5日 星期四

[2009-11-05-4] Android NDK - 6/49 大樂透

續用"6/49 大樂透"的source file(C language),改用Android NDK(Native Development Kit)來編譯Android應用程式。

Step1:
建立一個raylottery目錄(這裡用的是cupcake)
$ cd cupcake/development #移到android的development下
$ mkdir raylottery

Step2:
複製lottery.c到development. 可在這下載download here

Step3:
撰寫一個Android.mk(標準的檔名不要更動), 至於.mk的寫法可參考其他應該程式的寫法
$ find  ~/cupcake -name "Android.mk" > log_list_all  #找出cupcake下所有的Android.mk, 並存到 log_list_all

raylottery 下的Android.mk如下
# filename: Android.mk
# 2009-11-04, RayZ

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
    lottery.c
    
LOCAL_MODULE:= lottery_ray #module name
include $(BUILD_EXECUTABLE)

Step4:
編譯lottery_ray
$ cd ~/cupcake
$ make lottery_ray
編譯的結果會告知相對的文件位置: target thumb C(原始檔案), target Executable(可執行檔),target Non-prelinked, target Strip, Install。


查看一下lottery_ray 檔案格式, 確實是ARM, executable...
$ file rayout/target/product/generic/system/bin/lottery_ray 


Step5:
把產生的lottery_ray(四個位置的任一個皆可)放到adb shell來執行
$ adb devices #查看有那些device
$ adb shell mkdir /dev/ray_test  #在emulator-5554中做一個目錄
$ adb push rayout/target/product/generic/obj/EXECUTABLES/lottery_ray_intermediates/LINKED/lottery_ray /dev/ray_test #把lottery_ray 放到emulator-5554
$ adb shell  #進入adb shell
# cd /dev/ray_test
# ./lottery_ray


在AVD上用Terminal Emulator看到的畫面就和用adb shell一樣, 確實好玩。


ps:
1) 這裡已經把android 的out 目錄改為rayout,可以參考cupcake/build/buildspec.mk.default說明。
2) adb shell 的command可以在adb shell中的/system/bin找到。

[參考]
[1] 編譯 Native C 的 helloworld模塊
[2] 手工編譯 C 模塊
[3] Android Toolchain 與 Bionic Libc
[4] Google 釋出 Android 1.5 原生開發套件
[5] GNU toolchain
[6] Android 1.6 NDK, r1

[2009-11-05-4] Install Android SDK on Linux

Step1:
下載 Android SDK(Android SDK and AVD Manaer), 在這下載android-sdk_r3-linux.tgz [1]
ps: SDK(Software Development Kits), AVD(Android Virtual Devices)

Step2:
選定目錄,解壓gzip
$ tar -zxv -f android-sdk_r3-linux.tgz #解壓由tar 打包的gzip
$ mv android-sdk-linux ~  #把解壓出的folder 搬到 home 目錄
$ cd android-sdk-linux/tools   
$ ./android   #執行android tool, 開始準備安裝Android Platform/Docs ...

Step3:
選擇Available Packages 然後 Refresh, 若出現錯誤跳到Step4, 沒有就跳到Step5


Step4:
設定強制連網, 記得Save&Apply, 然後回Available Packages, Refresh就可以看到Packages


Step5:
選擇Platform, Docs


Step6:
選擇Accept All 和 Install Accepted


Step7:
安裝AVD, New 一個AVD吧


Step8:
在這裡的AVD Hardware 設定如下, 完成後就直接"Starts the selected AVD", 耐心等待第一次見面吧~


Step9:
初體驗的Android 2.0, 也順便換成繁體中文~


Step10:
用Android 2.0來上網看看, 可以上網,還真不錯哦~


Step11:
關機選項(直接打叉叉比較快)


[參考]
[1] Download the Android SDK
[2] android tool

2009年11月2日 星期一

Bash - 常用指令

# 若發生奇怪的錯誤可能是bash 被換成 dash
$ sudo dpkg-reconfigure dash  (answer no)
     # or sudo rm /bin/sh   sudo ln -s /bin/bash /bin/sh
     # see more information: wiki.ubuntu.com/DashAsBinSh
     
     # 15 - 顯示man的位置
$ which man

     # 14 - 查看檔案大小
$ ls -alh

     # 13 - 查看檔案格式
$ file ray.env.sh

     # 12 - 查看系統訊息
$ uname -a     

     # 11 - 變數
$ ws=~/Desktop/test_shell_script
$ cd $ws

     # 10 - 化名/取消化名
$ alias lm='ls -al |more'
$ lm
$ unalias lm
$ alias cls='clear'
$ alias dir='ls -l'
$ alias gogogo='sudo apt-get install'
$ alias raywork='~/Desktop/test_shell_script'

     # 9 - 直接看檔案內容
$ cat ray.sh

     # 8 - 指令搜尋的順序
$ type -a ls

     # 7 - 壓縮/解壓縮, 打包
$ bzip2 -k-z ray.sh        #保留原檔並壓成ray.sh.bz2
$ bzip2 -k-d ray.sh.bz2    #保留原檔並解壓成ray.sh
$ unzip NERD_tree.zip      #解壓
$ unzip -l NERD_tree.zip   #看壓縮檔案內容
$ unzip -c NERD_tree.zip   #看壓縮說明檔
$ tar -jcv -f filename.tar.bz2  dirname        #壓縮打包
$ tar -jtv -f filename.tar.bz2                 #查詢內容物
$ tar -jxv -f filename.tar.bz2  -C  dirname   #解壓到dirname

     # 6 - 斷字元的改變
$ dos2unix -k ray_dos.sh  # ^M$ 改成$
$ unix2dos -k ray_unix.sh # $ 改成 ^M$
$ dos2unix -kn ray_dos.sh ray_unix.sh  #保留原檔,新檔為ray_unix.sh

     # 5 - 歷史記錄
$ history
$ !22   #選第22個

     # 4 - 用source 來執行檔案/腳本,就可以執行於父程序中
$ source ray.env.sh

     # 3 - 找檔案,建議是先換成root來找. 
$ find / -name "ray.sh" | less
$ fine / -type d -name ".vim" | less #找目錄
$ su

     # 2 - 改變user登入
$ su  

     # 1 - 變成執行檔/改變檔案權限
$ chomd 770 ray.sh  


[參考]
[1] Unix vs DOS 指令對照表
[2] 鳥哥的Linux私房菜

2009年10月30日 星期五

[2009-10-30-5] GNU make - 6/49大樂透

在android中,Makefile都很大。對初學的我,不容易了解。寫了一個來幫助自己加深印象。用vim 當編輯器,gcc 當編譯器, make是用來串很多的c, h等多個檔案的工具,它也可以用bash指令,真是了不起。就來寫一個lottery的執行檔囉!!

Step1: 寫lottery.c~
//filename: lottery.c
//2009-10-30, RayZ, 6/49大樂透

#include 
#include 
#include 

int main(int argc, char* argv[])
{
    int i;
    int no;
    int in;   
    while(1)
    {  
     printf("\n1: lottery \
                \n0: exit \
             \nenter is ");
     while(scanf("%d", &in)!=1)
        {
            fflush(stdin);
            printf("that's error\n");
            return 0;
        }
        
        if(in == 0)
            break;
        
        else if(in != 1)
            printf("\nPlease enter:0~1\n");
        else
        {
         for (i=0;i<6;i++)
            {
                no = rand()%49+1;
                if(i==5)
                    printf("%d\n", no);
                else
                    printf("%d,", no); 
         }
        }  
    }
    return 0;
}


Step2: 寫Makefile~
# filename: Makefile
# 2009-10-30, RayZ

objects = lottery.o

dell = $(ibm)
ibm = $(phone) 
phone = number?

lottery: $(objects)
 @gcc -o lottery $(objects)
lottery.o: lottery.c
 @gcc -c lottery.c


all:
 @echo $(phone)  # @是不秀出echo命令 

.PHONY:clean      #預防目錄下真有一個clean file
clean:
 -@rm -f $(objects)  # -是rm出錯也不顯示


Step3: 編譯/執行~
$ make   #產生lottery.o, lottery
$ make clean #刪除lottery.o
$ make all #測試用
$ ./lottery #執行lottery, 看能不能中個大獎

用vim來編輯Makefile,要記得檢查vim的設定環境(~/.vimrc)是否有set et(展開跳格鍵)。如果有就把它移走吧(或是:set noet)。為了避免Makefile: *** missing separator.Stop.

DOWNLOAD Here

[參考]
[1] wiki - make
[2] GNU Make 使用手冊
[3] cplusplus - c library
[4] The Open Group - c library

2009年10月26日 星期一

[2009-10-26-1] Git - download AOSP on Linux ( Ubuntu 9.04 Desktop )

因著Android才慢慢發現GNU的世界真的和Windows的不太一樣,該這麼說呢! 或許就是新鮮吧!抱著這樣求知及冒險的態度,慢慢的也就習慣Linux的野性。

Git(System): 是一個version conrol的系統,方便local端做branching, commints(上傳修改), diffs(比對修改)以及 edits(編寫)。
Repo(Tool): 是一個可以讓你更容易下載/上傳AOSP的工具, repo的指令是用Python script寫成。所以,抓AOSP我們會用repo 來完成。

Step1: 環境套件安裝(32-bit x86)
$ sudo apt-get install git-core gnupg sun-java5-jdk\
flex bison gperf libsdl1.2-dev libesd0-dev zip curl\
libwxgtk2.6-dev build-essential gawk expect gettext\
zlib1g-dev valgrind libreadline5-dev libncurses5-dev

Step2: 安裝Repo
$ cd ~  #到home目錄
$ mkdir bin  #產生bin目錄
$ echo $PATH #確定bin有在PATH中
$ curl http://android.git.kernel.org/repo >~/bin/repo  #抓檔案並存到repo file
$ chmod a+x ~/bin/repo #設成可執行權限

Step3: 初始Repo
$ mkdir mydroid   #產生mydroid目錄
$ cd mydroid #到mydroid
$ repo init -u git://android.git.kernel.org/platform/manifest.git
在初始成功"repo initialized in /mydroid"之前,會要求填入真實姓名/email(若要和Google溝通則填寫,一般是不用寫的)。另外若有改寫manifest.xml, 發現是不會覆寫舊的manifest.xml

Step3: 下載AOSP
$ repo sync

Step4: 建code
$ cd ~/mydroid
$ make  

[參考]
[1] AOSP - get source

2009年10月25日 星期日

[2009-10-25-7] Git - download AOSP on Windows

嘗試把在linux下抓到的AOSP放到windows,看來有些檔案(權限)無法copy。真不方便,還好有[1]的方法,才可以在winodws一窺AOSP的秘密。
下列是我的方法:
Step1: 下載 msysGit-netinstall-1.6.4-preview20090730.exe
Step2: 執行/安裝後,選Git Bash,如[1]提到的會出現git shell
Step3:
$mkdir raydroid
Step4: 下載getcode.bat到raydroid, 其中裡面所有的repository(程式下載點)來自於[3]
Step5:
$ getcode.bat
如果是第一次,就靜靜等待把code 抓完吧!若不是就判斷一下要不要保留or刪除重抓囉!!

[參考]
[1] ysl的程式天堂 - 如何在Windows平台上下載Android的原始碼?
[2] msysgit - Git on Windows
[3] anDROID open source project

2009年10月23日 星期五

Download - source code

2009-10-23-5

本想說把source code 放到[1], 若是想要用的時候把它剪下/貼上就可以。事與願違,網頁的"空白"及"tab"鍵也就是文檔的縮排不同設定,導致程式無法正常執行如Python,所以就只好把source code 放到這兒。方便使用~

DOWNLOAD Here
檔案包括lottery, lottery.c, lottery.o, Mackfile

DOWNLOAD Here
檔案包括.vimrc, broadcast.sh, ray.env.sh, ray.py, ray.sh, ray.vim-em

$ tar -jcv -f notes.tar.bz2  notes  #壓縮打包
$ tar -jtv -f notes.tar.bz2  #查詢內容物
$ tar -jxv -f notes.tar.bz2 -C notes  #解壓到notes這個目錄

[參考]
[1] 高登工作室 - 在Blogger文章中插入程式
[2] 鳥哥 - 打包指令

2009年10月22日 星期四

[2009-10-22-4] Python - 6/49大樂透

#!/usr/bin/env python
# -*- coding: UTF-8 -*-


#file name: ray.py
#2009-10-16, RayZ, demo cases/notes using python
#第二行是用來寫中文註解

#this file can be execution if the first row has #!/usr/bin/env python. usage is 
#chomd 770 ray.py
#./ray.py
# or using $ python ray.py in command line (it is txt file)

# look for Python's built in functions using Python command line
# >>> import __builtin__
# >>> dir(__builtin__)

def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
    while 1:
        ok = raw_input(prompt) 
        if ok in ('y', 'ye', 'yes'): return 1
        if ok in ('n', 'no', 'nop', 'nope'): return 0
        retries = retries - 1
        if retries < 0: raise IOError, 'refusenik user'
        print complaint    
    
def f91(a, l = []):
    l.append(a)
    return l
def f92(a, l = None):
    if l is None:
        l = []
    l.append(a)
    return l


while 1: 
    Title = "\n\
    Example 10: 避開共用值\n\
    Example 9: 6/49大樂透\n\
    Example 8: function repeat\n\
    Example 7: 質數for loop's else\n\
    Example 6: range\n\
    Example 5: 費氏數列\n\
    Example 4: 字串\n\
    Example 3: if\n\
    Example 2: if\n\
    Example 1: Hello\n\
    0:Quit\n\
    Please enter a number: "
    setNo = int(raw_input(Title))
    print "\n"

    if setNo == 10:
        print "function point", f91, f92
        print "第一次呼叫 f91(5)=", f91(5), ",f92(1)=", f92(1)
        print "第二次呼叫 f91(6)=", f91(6), ",f92(2)=", f92(2)
        print "第三次呼叫 f91(7)=", f91(7), ",f92(3)=", f92(3)
        
    elif setNo == 9:
        import random
        l = []
        for n in range(-1,5):  # 5 - (-1) 個
            l.append(random.randint(1,49))
        print l
    
    elif setNo == 8:
        ask_ok('Do you really want to quit?')
        ask_ok('Ok, to overwrite the file?', 10)
       
    elif setNo == 7:
        for n in range(2, 10):
            for x in range(2, n):
                if n % x == 0:
        print n, 'equals', x, '*', n/x
        break
     else: # for's else, # special usage
         print n, 'is a prime number'

    elif setNo == 6:
        a = ['Mary', 'had', 'a', 'little', 'lamb']
        for i in range(0, len(a), 2):
            print i, a[i]
    elif setNo == 5:
        a, b = 0, 1
        while b < 10:
            print b, 
            a, b = b, a + b
        print "\n"
        
    elif setNo == 4:
        x = y = z = 0 
        print "x =";x
        print "x =",x
        word='Hel'+'p '
        print word*5

    elif setNo == 3:
        x = int(raw_input("Please enter a number: "))
        if x<0:
            x = 0
            print "Negative changed to zero"
        elif x==0:
            print "Zero"
        elif x==1:
            print "Single"
        else:
            print "More"

    elif setNo == 2:
        a = 5
        b = 5.5
        if b > a:
            print "b is more than a !\n"
        else:
            print "b is less than a !\n"

    elif setNo == 1:
        print "This is Python -- Hello.world!"
        print ("Hello.world!\n")

    elif setNo == 0:
        print "Quit Example"
        break

    else:
        print "Please enter a number(0~8)\n"

[參考]
[1] Python 教學文件
[2] 隨機數與隨機字符串
[3] PythonDOC

[2009-10-22-4] Shell scripts - 6/49大樂透

#!/bin/bash
#file name: ray.sh
#2009-10-09, RayZ, demo cases/notes using bash

#第一行可以讓這個file變成執行檔,方法是
#chomd 770 ray.sh
#./ray.sh 
# or 是一般文字檔就必須sh ray.sh

#--------------以下是手動在 bash 下執行

#0 若發生奇怪的錯誤可能是bash 被換成 dash
#$    sudo dpkg-reconfigure dash  (answer no)
       # or sudo rm /bin/sh   sudo ln -s /bin/bash /bin/sh
       # see more information: wiki.ubuntu.com/DashAsBinSh

#1 變數
#$   ws=~/Desktop/test_shell_script
#$   cd $ws

#2 化名/取消化名
#$   alias lm='ls -al |more'
#$   lm
#$   unalias lm
#$   alias cls='clear'
#$   alias dir='ls -l'
#$   alias gogogo='sudo apt-get install'
#$   alias raywork='~/Desktop/test_shell_script'

#3 直接看
#$   cat ray.sh

#4 指令搜尋的順序
#$   type -a ls

#5 壓縮/解壓縮, 打包
#$   bzip2 -k-z ray.sh   #保留原檔並壓成ray.sh.bz2
#$   bzip2 -k-d ray.sh.bz2    #保留原檔並解壓成ray.sh
#$   unzip NERD_tree.zip  #解壓
#$   unzip -l NERD_tree.zip #看壓縮檔案內容
#$   unzip -c NERD_tree.zip #看壓縮說明檔
#$   tar -jcv -f filename.tar.bz2  dirname  #壓縮打包
#$   tar -jtv -f filename.tar.bz2  #查詢內容物
#$   tar -jxv -f filename.tar.bz2  -C  dirname   #解壓到dirname

#6 斷字元的改變
#$   dos2unix -k ray_dos.sh  # ^M$ 改成$
#$   unix2dos -k ray_unix.sh # $ 改成 ^M$
#$   dos2unix -kn ray_dos.sh ray_unix.sh  #保留原檔,新檔為ray_unix.sh

#7 歷史記錄
#$   history
#$   !22   #選第22個

#8 用source 來執行檔案/腳本,就可以執行於父程序中
#$   source ray.env.sh


#9 找檔案,建議是先換成root來找. 
#$   find / -name "ray.sh" | less
#$   fine / -type d -name ".vim" | less # 找目錄
#$   su

#10 改變user登入
#    su

#11 改變檔案權限
#    chmod 770 ray.sh   


#--------------以下是bash file
#需要在 bash 下執行
#ex: vadmin@vadmin:~$ sh ray.sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
#把自定變數轉成環境變數
export PATH    

 
s1='demo case No. (1~10)'
echo -e "\n\n1) 在bash中輸入名字並印出全名 \
         \n2) 6/49大樂透 \
         \nq/Q) Exit \
         \n"
read -p "Select $s1: " democase


function exitfun(){
if [ "$democase" == "q" ] || [ "$democase" == "Q" ]; then
        echo -e "\nExit OK"
        exit 0
else
        echo " Error!! choose $s1 "
fi
}

case $democase in
     "1")
 #在bash中輸入名字並印出全名
 read -p "Please input your first name:  " firstname
 read -p "Please input your last name:   " lastname
 echo -e "\nYour full name is: $firstname $lastname "
 ;;
     "2")
        #RANDOM: 0~32767
        #6/49大樂透
        i=0
        while [ "$i" != "7" ]
        do
          i=$(($i+1))
          declare -i nu=$RANDOM*49/32768+1
          echo -n "$nu "          
        done                     
 ;;     
     *)
        exitfun;        
 ;;
esac

sh ray.sh


[參考]
[1] 鳥哥 - 學習Shell Scripts
[2] 鳥哥 - 如何改變檔案屬性與權限

[2009-10-22-4] Emacs - 常用指令


M-x switch-to-buffer #1 切換buffer
M-x rename-buffer #2 改變buffer name
M-x shell #3 開啟一個shell

Vim - 常用指令


:set nu #1 顯示行號
:open [filename] #2 打開檔案
:files #3 看開了那些檔案
:n #4 編下個檔
:N #5 編上個檔
:sp [filename] #6 分割視窗
ctrl+w+(up-key) #7 切換到上視窗
:w! #8 強制寫入
:wq #9 寫入離開
yy #10 複製行
dd #11 刪除行
p #12 貼上
gg #13 到首行
G #14 到最後一行


[參考]
[1] vi指令說明完整版
[2] 鳥哥的Linux私房菜

[2009-10-22-4] BASH - mplayer 聽廣播


#!/bin/bash
#file name: broadcast.sh
#2009-09-24, RayZ, First script, 中廣音樂網

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
mplayer mms://bcr.media.hinet.net/RA000007

#執行成功的代碼
exit 0

若是沒裝mplayer, 就給它 sudo apt-get install mplayer 囉!!

2009年10月21日 星期三

[2009-10-21-3] BASH - alias 化名

#!/bin/bash
#file name: ray.env.sh
#2009-10-14, RayZ,

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
#把自定變數轉成環境變數
export PATH    


#0 若發生奇怪的錯誤可能是bash 被換成 dash
#$    sudo dpkg-reconfigure dash  (answer no)
       # or sudo rm /bin/sh   sudo ln -s /bin/bash /bin/sh
       # see more information: wiki.ubuntu.com/DashAsBinSh

#$ source ray.env.sh #可以成為父的shell, 若是用sh ray.env.sh只是子的shell

alias gogogo='sudo apt-get install'             #ORZ
alias raywork='cd ~/Desktop/test_shell_script'  #ORZ
alias py='python'                               #ORZ
alias lm='ls -al'                               #ORZ
  
cat ray.env.sh | grep '#ORZ' -n | cut -c -50  #抓出特定字再刪除第50以後的字元, 行號的個數。
其中,
cat(ConcAtenaTe/使連接): 把ray.env.sh 內容印到stdout(就是螢幕囉)。
grep(搜尋) '#ORZ' -n: 找出'#ORZ'字串並且列出行號, 類似google。
cut(剪去) -c -50: 保留50個字元, 其他移除,其中50個字元也包含 -n的行號字元。
另外,記得用$ source ray.env.sh #若用sh ray.env.sh則shell會認不到哦!
[參考]
[1] 鳥哥 - 命令別名設定
[2] 鳥哥 - 擷取命令

[2009-10-21-3] Vim - 外掛程式 NERD tree

在vim下,也可以有樹狀目錄了,實際用起來真的很順手,快速鍵也不用記太多。



安裝的方法:
Step1: 下載 NERD_tree.zip [2]
Step2:

$ mkdir -p ~/.vim #若沒有, 建立一個隱藏目錄vim
$ unzip -d ~/.vim NERD_tree.zip #解壓至.vim, 沒有.vim也無所謂啦
$ vim #進入vim編輯環境, 並輸入:NERDTree
就可以看到NERD tree 樹狀目錄。

Notes:
視窗切換 - 快速鍵
<C+w>: Ctrl + w 可用來切換split視窗
<C+w, j>: 往下方的視窗切換
<C+w, k>: 往上方的視窗切換


"file name: .vimrc
"2009-10-20, RayZ
"這個檔案的雙引號(")是註解


nnoremap <silent> <F5> :NERDTree<CR> "把F5功能鍵當做:NERDTree

"nu 顯示行號, et 展開跳格鍵, ts=4 指定跳格字元
"sw=4 偏移字元寬, cino=>4 C式縮排
set nu et ts=4 sw=4 cino=>4
"set hlsearch "高亮度反白
set backspace=2 "可隨時用倒退鍵刪除
set autoindent "自動縮排
set ruler "可顯示最後一行的狀態
set showmode "左下角那一行的狀態
set bg=dark "顯示不同的底色色調
syntax on "進行語法檢驗,顏色顯示

至於vim的高亮, 行號等環境設定,可以把.vimrc 放到~就可以了。當然,你想要每次都有不一樣的感覺,也是可以在vim中,自己打上面的命令。例如: 不想要行號(:set nonu), 不想要高亮度反白(:set nohlsearch)

[參考]
[1] Vim 樹狀目錄外掛: NERDTree
[2] The NERD tree : A tree explorer plugin for navigating the filesystem
[3] 鳥哥 - vim環境設定與記錄

2009年10月2日 星期五

[2009-10-02-5] Ubuntu - 修改語言別、輸入法、解析度

2009-10-02-5

修改語言別:
Systme>Administration>Language Support
選定中文(台灣)就可以"Install/Remove Languages",之後,就在登入畫面的選單(Options)做改變囉!


------------------------------------------

嘸蝦米輸入法:
換上中文介面後,再來就是裝上最常用的嘸蝦米輸入法。

1)下載Liu.bin,到Ubuntu的 "/usr/share/scim/tables"
2)系統>偏好設定>SCIM輸入法設定 即可。


[參考]
[1] Open Source 實驗室 - 嘸蝦米 for linux
[2] 摩托學園討論區 - Linux 嘸蝦米完美安裝法

PS: 我自己是用[1]的方法。上次有看到網友分享嘸蝦米 for anDROID,等anDROID手機到手再和大家分享囉!
------------------------------------------

解析度設定:
系統>偏好設定>顯示 解析度( 選1280x768(16:10) )

[2009-10-02-5] VMPlayer - 修改 Recent Virtual Machines

用虛擬機器VMware Player有個好處就是當不小心把Ubuntn給玩掛了,只要再Open一次VMX就可以了。當然之前玩掛的可以保留(建議是改一下名字做區別),等將來功力增加時,再來解決囉!



在Windows XP下更改的方法:
1) 找到 \Documents and Settings\username\Applicaton Data\VMware\perferences.ini
2) 打開後,可以找到如下的描述(改成你想要的即可)

pref.mruVM0.filename = "D:\Starfruit_VMX\Ubuntu 9.04 Desktop_II\Ubuntu 9.04 Desktop.vmx"
pref.mruVM0.displayname = "Ubuntu 9.04 Desktop"
pref.mruVM1.filename = "D:\Starfruit_VMX\Ubuntu 9.04 Desktop\Ubuntu 9.04 Desktop.vmx"
pref.mruVM1.displayname = "Ubuntu 9.04 Desktop(有問題的)"

[參考]
ericmartin - Clearing VMWare Player Recent Virtual Machines list

2009年10月1日 星期四

[2009-10-01-4] Ubuntu - 我的 Linux

爬了好多關於Ubuntu Linux文章,發現很多網友還是離不開Windows的便利和習慣,紛紛把Ubuntu 架在虛擬機器上。我也不例外,看了軟體工匠R的筆記就選定VMware Player囉! 用它的好處是免費的虛擬機器、免費的VAM(Virtual Appliance Marketplace)、安裝容易。

1) 下載VMware Player
2) 下載你想要的 VAM(VMX)

等一切安裝好就可以看鳥哥的Linux私房菜來把玩一下Ubuntu Linux囉!