2 #// Content-Type: text/plain; charset=utf-8
3 #// -eE オプションは、エラーが起きたら中断します
4 #// -x オプションは、1行ずつコマンドを表示します
6 #// bashlib-prompt is provided under 3-clause BSD license.
7 #// Copyright (C) 2011 Sofrware Design Gallery "Sage Plaisir 21" All Rights Reserved.
12 local obj="g_InputCommandOpt"
14 #//=== call InputCommand_func
15 SetAttr_func $obj Class "InputCommandOpt"
16 SetAttr_func $obj Lead "bashlib menu - shorthand prompt"
18 SetAttr_as_AssociativeArrayName_func $obj CommandReplace \
27 "Help" "Help_sth_func" \
28 "SearchFile" "SearchFile_sth_func" \
29 "NewSh" "NewSh_sth_func" \
30 "NewMenu" "NewMenu_sth_func" \
31 "Extract" "Extract_sth_func" \
32 "chmod_x" "chmod_x_sth_func" \
33 "Test" "Test_sth_func" \
35 SetAttr_as_AssociativeArrayName_func $obj MenuCaption \
36 "1" "ヘルプを開く (HTML5+SVG 対応ブラウザ Chrome, Safari で見えます) [Help]" \
37 "2" "ファイルを検索する [SearchFile]" \
38 "3" "新規作成する - bashlib が使えるシェル・スクリプト・ファイル [NewSh]" \
39 "4" "新規作成する - ショートハンド・プロンプトのメニュー [NewMenu]" \
40 "5" "圧縮ファイルを解凍する。ファイル名を一覧する [Extract]" \
41 "6" "拡張子から実行属性を設定/解除する [chmod_x]" \
42 "7" "bashlib の自動テストを実行する [Test]" \
44 InputCommand_func $obj "" "$1" "$AppKey"
48 if [ "${BASH_VERSINFO[0]}" -ge "4" ];then
49 declare_AssociativeArrayClass="declare -A"
51 declare_AssociativeArrayClass="declare"
54 export g_AssociativeArrayMaxLength=100
55 $declare_AssociativeArrayClass g_InputCommandOpt
59 #//*********************************************************************
60 #// <<< [Help_sth_func] >>>
61 #//*********************************************************************
62 function Help_sth_func()
64 local abs_path ; GetAbsPath_func "document/bashlib.html" ; abs_path="$g_Ret"
68 apps=( "Google Chrome" "Safari" )
69 GetUsableApplicationsForMac_func commands "${apps[@]}" #//[out] commands
70 if [ "${commands[0]}" != "" ];then
71 echo ${commands[0]} "file://$abs_path"
72 eval ${commands[0]} "file://$abs_path" &
77 apps=( "google-chrome" "firefox" )
78 GetUsableCommands_func commands "${apps[@]}" #//[out] commands
79 if [ "${commands[0]}" != "" ];then
80 echo ${commands[0]} "file://$abs_path"
81 eval ${commands[0]} "file://$abs_path" &
90 #//*********************************************************************
91 #// <<< [SearchFile_sth_func] >>>
92 #//*********************************************************************
93 function SearchFile_sth_func()
100 echo "Enter のみ: $g_StartInPath"
101 InputPath_func "検索するフォルダーのパス >" \
102 --ChkFolderExists --AllowEnterOnly ; search_path="$g_Ret"
103 if [ "$search_path" == "" ];then search_path="$g_StartInPath" ;fi
104 StringClass.cutLastOf_method "$search_path" "/" ; search_path="$g_Ret"
107 echo "Enter のみ: すべてのファイル"
108 Input_func "ファイル名のフィルター 例 *.txt >" ; filter="$g_Ret"
111 echo "Enter のみ: 内容は問わない"
112 Input_func "キーワード >" ; keyword="$g_Ret"
115 echo "Search $keyword in $search_path/$filter"
117 if [ "$keyword" == "" ];then
118 if [ "$filter" == "" ];then
119 find "$search_path" -print
121 find "$search_path" -name "$filter" -print
124 StringEscapeUtilsClass.escapeGrep_method "$keyword" ; keyword="$g_Ret"
125 if [ "$filter" == "" ];then
126 grep -rni "$keyword" "$search_path" || : #// : ignores exit status
128 grep -rni --include="$filter" "$keyword" "$search_path" || : #// : ignores exit status
135 #//*********************************************************************
136 #// <<< [NewSh_sth_func] >>>
137 #//*********************************************************************
138 function NewSh_sth_func()
140 NewShSub_sth_func "sample/Sample.sh" "$@"
144 function NewShSub_sth_func()
146 local TemplatePath="$1"
151 local default_name="a.sh"
154 echo "Enterのみ : カレントの $default_name"
155 InputPath_func "新しいファイルのパス >" --AllowEnterOnly ; path="$g_Ret"
156 if [ "$path" == "" ];then path="$default_name" ;fi
157 GetAbsPath_func "$path" "$g_StartInPath" ; path="$g_Ret"
158 if [ ! -e "$path" ];then break ;fi
159 if [ -d "$path" ];then path="$path/$default_name" ; break ;fi
160 echo "<ERROR msg=\"すでにファイルが存在します。\"/>" >&2
163 GetParentAbsPath_func "$path"
165 AppKeyClass.newWritable_method "$AppKey" "$parent_path"
168 mkdir_func "$parent_path"
169 cp "$TemplatePath" "$path"
171 echo "$path を作成しました。"
173 #// search scriptlib folder
175 if [ -e "$parent_path/scriptlib" ];then break ;fi
176 if [ "$parent_path" == "/" ];then parent_path="" ; break ;fi
177 parent_path=`dirname "$parent_path"`
180 #// make scriptlib folder
181 if [ "$parent_path" == "" ];then
182 GetParentAbsPath_func "$path"
184 cp -Rap "scriptlib" "$parent_path"
185 echo "$parent_path/scriptlib フォルダーを作成しました。"
189 name=`basename "$path"`
190 echo "シェルから、『./$name』と入力すると起動できます。"
195 #//*********************************************************************
196 #// <<< [NewMenu_sth_func] >>>
197 #//*********************************************************************
198 function NewMenu_sth_func()
200 NewShSub_sth_func "sample/Menu.sh" "$@"
205 #//*********************************************************************
206 #// <<< [Extract_sth_func] >>>
207 #//*********************************************************************
208 function Extract_sth_func()
214 InputPath_func "圧縮ファイルのパス >" --ChkFileExists ; package_path="$g_Ret"
218 echo "Enterのみ : ファイル名を一覧する"
219 echo "[Ctrl]+[C] : 中断"
220 InputPath_func "解凍先フォルダーのパス >" --AllowEnterOnly ; target_path="$g_Ret"
222 if [ "$target_path" == "" ];then
223 echo "$package_path | less"
225 ListUpIn_func "$package_path" | less
227 AppKeyClass.newWritable_method "$AppKey" "$target_path"
228 Extract_func "$package_path" "$target_path"
236 #//*********************************************************************
237 #// <<< [chmod_x_sth_func] >>>
238 #//*********************************************************************
239 function chmod_x_sth_func()
246 defaults="$g_StartInPath"
248 echo "Enterのみ : $defaults"
249 InputPath_func "処理を行うフォルダーのパス >" --AllowEnterOnly --ChkFolderExists
251 if [ "$work_folder" == "" ];then work_folder="$defaults" ;fi
255 echo "Enterのみ : $defaults"
256 Input_func "実行属性を設定するファイル(\".\"=設定しない, CSV形式)>" ; set_paths="$g_Ret"
257 if [ "$set_paths" == "" ];then set_paths="$defaults" ;fi
259 defaults="*.txt, *.html, *.svg"
261 echo "Enterのみ : $defaults"
262 Input_func "実行属性を解除するファイル(\".\"=解除しない, CSV形式)>" ; unset_paths="$g_Ret"
263 if [ "$unset_paths" == "" ];then unset_paths="$defaults" ;fi
265 chmod_x_func "$work_folder" "$set_paths" "$unset_paths"
270 #//*********************************************************************
271 #// <<< [Test_sth_func] >>>
272 #//*********************************************************************
273 function Test_sth_func()
275 if [ -e "test_patch" ];then
276 cp -Rap "../test" "."
277 cp -Rap test_patch/* "test"
286 #//*********************************************************************
287 #// <<< [T_Error_sth_func] >>>
288 #//*********************************************************************
289 function T_Error_sth_func()
291 Error_func "エラーメッセージのテスト"
302 #//--- start of bashlib include ------------------------------------------------------
304 #// <<< set up bashlib and call Main_func >>>
306 #// bashlib is provided under 3-clause BSD license.
307 #// Copyright (C) 2011 Sofrware Design Gallery "Sage Plaisir 21" All Rights Reserved.
309 g_BashLibPath="scriptlib/bashlib_inc.sh"; g_Ver="1.0"
310 g_StartInPath=`pwd`; cd "`dirname "$BASH_SOURCE"`"; g_Arguments=( "$BASH_SOURCE" "$@" )
311 for (( i = 0; i < 20; i ++ ));do
312 if [ -e "$g_BashLibPath" ];then break ;else g_BashLibPath="../$g_BashLibPath" ;fi ;done
313 if [ "$i" == "20" ];then echo "${g_BashLibPath##*../} が見つかりません。
314 bashlib $g_Ver をダウンロードして scriptlib フォルダーをコピーしてください。"; exit 1 ;fi
315 source "$g_BashLibPath" #// include
317 #//--- end of bashlib include --------------------------------------------------------