[UP/add] - add virtualbox script to conf net,
[arrow.git] / archlinux_conf / home / .bin / shell / ge
blob641960593801e18005e345fcf5149ba989d65f95
1 #!/bin/bash
2 #author: arrow
3 #copyright(c) 29/06/2006 arrowworld@gmail.com
4 #use: enhance my vim, implement remote server, and use tab
6 . arrow-lib
7 GEO="-geom 106x37+0+25"
8 V_EXEFILE="gvim"
9 V_CURRENT_DIR="`pwd`"
10 #hostname will change to uppercase
11 #V_SERVERNAME="`hostname`"
12 if [ "$1" = "" ]; then
13 echo "check parameter please"
14 exit 0
16 V_SERVERNAME="$1"
17 shift
18 V_SERVERNAME=`echo "$V_SERVERNAME" | tr "a-z" "A-Z"`
19 V_REMOTE_TAB_SILENT="--remote-tab-silent"
20 #set to empty if you do like it
21 #V_REMOTE_TAB_SILENT=""
22 V_KEEP_DIR=""
23 V_KEEP_QUIET=""
24 V_NEED_WAIT="`$V_EXEFILE --serverlist | grep "$V_SERVERNAME" | grep -v grep`"
25 #test for go on if has error
26 V_SHOULD_EXIT=""
27 V_HAS_ERROR="$V_SERVERNAME"
28 if [ "$V_NEED_WAIT" = "" ]; then
29 echo "NEED wait: yes"
30 else
31 echo "NEED wait: no"
33 #V_FILENAMES="$*"
34 #set -- `getopt "ks" "$@"`
35 set -- `getopt "ks" "$@"`
36 while [ ! -z "$1" ]
38 case "$1" in
39 -k) #keep current dir
40 V_KEEP_DIR="YES";;
41 -s) #silent, do not echo msg when open a file
42 V_KEEP_QUIET="YES";;
43 *) break;;
44 esac
45 #delete this parameter
46 shift
47 done
48 #delete --
49 shift
51 #----------function open file with editor
52 function arrow_change_dir()
54 if [ "$V_HAS_ERROR" != "" ] && [ "$V_KEEP_DIR" != "YES" ]; then
55 #sleep 1
56 "$V_EXEFILE" --servername "$V_SERVERNAME" --remote-send ":lcd $V_CURRENT_DIR<CR>:<CR>"
57 echo "send lcd success"
60 function arrow_openfile()
62 #first parameter is the filename
63 if [ "$V_KEEP_QUIET" != "YES" ]; then
64 echo -e "server open: ${CL_GREEN}$1${CL_END}"
66 # "$V_EXEFILE" $GEO --servername "$V_SERVERNAME" "$V_REMOTE_TAB_SILENT" "$1" 2>/dev/null
67 $V_EXEFILE $GEO --servername $V_SERVERNAME $V_REMOTE_TAB_SILENT "$1"
68 # usleep 600000
69 sleep 1
70 if [ "$V_NEED_WAIT" != "$V_SERVERNAME" ]; then
71 sleep 2
72 #arrow_change_dir #now change dir at init
74 #check open gvim success, bcs remote used with x server only
75 V_HAS_ERROR="`$V_EXEFILE --serverlist | grep "$V_SERVERNAME" | grep -v grep`"
77 #----------function end
78 #V_GVIM="-g"
79 #remove it for a while, we can use {EXE} -g {FILENAME} to open files
81 #check parameter at first, echo err msg if is empty
82 if [ "$1" = "" ]; then
83 echo "arrow: make sure has file name -_-"
84 arrow_openfile "/tmp/tmp"
85 exit 0
88 #now open file with loop
89 echo -e "server name: [${CL_YELLOW}$V_SERVERNAME${CL_END}]"
91 until [ -z "$1" ]
93 #check err no, ask for go on
94 #check if here does not exists a xserver, ask for continue
95 if [ "$V_HAS_ERROR" = "" ]; then
96 echo "ERROR: here may do not exists a x server"
97 echo -n "->Question: do you want open rest files(y,n) "
98 read V_SHOULD_EXIT
99 if [ "$V_SHOULD_EXIT" != "y" ]; then
100 echo "END: check your xserver"
101 exit 0
104 #open file now
105 arrow_openfile "$1"
106 #revert wait variable
107 if [ "$V_NEED_WAIT" != "$V_SERVERNAME" ]; then
108 V_NEED_WAIT="$V_SERVERNAME"
110 shift
111 #arrow_change_dir #change current dir for every file to local
112 done
114 #end
116 # $Log:
117 # v1.0 create open gvim server with remote command
118 # v1.1 fix can not open multi files, set current dir for new file
119 # v1.2 fix open file will wait every time when exec "ge"
120 # UP: ask for to open rest files when can not open xserver
121 # and do not send lcd command when open xserver fail