[SCM] Lisaac scripts branch, master, updated. 9d15425da463f211f06c042390775d6525e4a78e
Mildred Ki'Lya
silkensedai at online.fr
Tue Aug 25 14:32:11 UTC 2009
The following commit has been merged in the master branch:
commit 9d15425da463f211f06c042390775d6525e4a78e
Author: Mildred Ki'Lya <silkensedai at online.fr>
Date: Tue Aug 25 16:29:41 2009 +0200
Added magic-script (formely known as k)
This script can do many things, just start it with the -h option for more help.
It is heavily documented. Among the main features, there is:
- run grep on lisaac files
- run kwrite (it can run kate, but there are bugs in kate) given the name of a
prototype
- can search different directories (add @lib on the command line can search
through the library)
It can be configured by a .Kprefs in the current directory. There is such a file
on the compiler git repository.
diff --git a/magic-script b/magic-script
new file mode 100755
index 0000000..dca2e9c
--- /dev/null
+++ b/magic-script
@@ -0,0 +1,256 @@
+#! /bin/zsh
+
+exit_status=0
+
+op_help=false
+op_sess=
+op_file=
+op_dir=.
+has_op_dir=false
+op_verb=false
+op_show=false
+op_grep=false
+op_egrep=false
+op_grep_pattern=
+
+while true; do
+ case "$1" in
+ --help) op_help=true; break ;;
+ --verbose) op_verb=true ;;
+ --dir) op_dir=$2; has_op_dir=true; shift ;;
+ --show) op_show=true ;;
+ --grep) op_grep=true ; op_grep_pattern=$2; shift ;;
+ --egrep) op_egrep=true; op_grep_pattern=$2; shift ;;
+ @*) op_sess=${1[2,-1]} ;;
+ --) shift; break ;;
+ --*) echo "`basename "$0"`: unknown option $1" >&2; exit 1 ;;
+ -*)
+ opts="$1"
+ opts="${opts[2,-1]}"
+ while [[ -n "$opts" ]]; do
+ case "${opts[1]}" in
+ h) op_help=true ;;
+ v) op_verb=true ;;
+ d) op_dir=$2; has_op_dir=true; shift ;;
+ s) op_show=true ;;
+ g) op_grep=true ; op_grep_pattern=$2; shift ;;
+ G) op_egrep=true; op_grep_pattern=$2; shift ;;
+ *) echo "`basename "$0"`: unknown option -${opts[1]}" >&2; exit 1 ;;
+ esac
+ opts="${opts[2,-1]}"
+ done
+ ;;
+ *) break ;;
+ esac
+ shift
+done
+
+if [[ $# -ge 1 ]]; then
+ op_file="$1"
+ shift
+fi
+
+if $op_verb; then
+ msg_v=(msg -)
+ msg_l=(msg l)
+else
+ msg_v=(true)
+ msg_l=(true)
+fi
+
+# http://en.wikipedia.org/wiki/ANSI_color
+c_u="\033[4m" # underline
+c_b="\033[1m" # bold
+c_b_black="\033[1;30m"
+c_b_red="\033[1;31m"
+c_b_green="\033[1;32m"
+c_b_yellow="\033[1;33m"
+c_b_blue="\033[1;34m"
+c_b_magenta="\033[1;35m"
+c_b_cyan="\033[1;36m"
+c_b_white="\033[1;37m"
+c_black="\033[30m"
+c_red="\033[31m"
+c_green="\033[32m"
+c_yellow="\033[33m"
+c_blue="\033[34m"
+c_magenta="\033[35m"
+c_cyan="\033[36m"
+c_white="\033[37m"
+c="\033[1;0m"
+
+msg(){
+ mode="$1"
+ shift
+ case "$mode" in
+ t)
+ echo -e "$c_b_white$*$c"
+ ;;
+ e)
+ echo -e "$c_b_red==>$c $c_b_white$*$c" >&2
+ ;;
+ q)
+ echo -ne "$c_b_cyan$*$c " >&2
+ ;;
+ l)
+ echo -e "$c_cyan$*$c " >&2
+ ;;
+ *)
+ echo "$@"
+ ;;
+ esac
+}
+
+if $op_help; then
+ self=`basename "$0"`
+ msg t "NAME"
+ msg - ""
+ msg - " ${c_b}$self${c} - Better CLI for Kate"
+ msg - ""
+ msg t "SYNOPSYS"
+ msg - ""
+ msg - " ${c_b}`basename "$0"`${c} [ ${c_u}OPTIONS${c} ] [ ${c_b}--${c} ] [ ${c_u}FILE${c} ]"
+ msg - ""
+ msg t "DESCRIPTION"
+ msg - ""
+ msg - " Open in Kate the files described by ${c_u}FILE${c}."
+ msg - ""
+ msg t "OPTIONS"
+ msg - ""
+ msg - " ${c_b}-h${c}, ${c_b}--help${c}"
+ msg - " Display this help"
+ msg - ""
+ msg - " ${c_b}@${c}${c_u}SESSION${c}"
+ msg - " Use kate session named ${c_u}SESSION${c}"
+ msg - ""
+ msg - " ${c_b}-d${c}, ${c_b}--dir${c} ${c_u}DIR${c}"
+ msg - " Search for the file ${c_u}FILE${c} in the directory ${c_u}DIR${c}"
+ msg - ""
+ msg - " ${c_b}-s${c}, ${c_b}--show${c}"
+ msg - " Only show files found, one file per line that you can pipe"
+ msg - " to xargs like: | xargs grep -n ${c_u}REGEXP${c}"
+ msg - ""
+ msg - " ${c_b}-g${c}, ${c_b}--grep${c} ${c_u}REGEXP${c}"
+ msg - " Grep the files found using ${c_u}REGEXP${c}"
+ msg - " Uses grep -n"
+ msg - ""
+ msg - " ${c_b}-G${c}, ${c_b}--egrep${c} ${c_u}REGEXP${c}"
+ msg - " Grep the files found using ${c_u}REGEXP${c}"
+ msg - " Uses egrep -n"
+ msg - ""
+ msg - " ${c_b}-v${c}, ${c_b}--verbose${c}"
+ msg - " Be verbose"
+ msg - ""
+ msg t "CONFIGURATION"
+ msg - ""
+ msg - " ${c_b}$self${c} can be configured using a file ${c_u}.Kprefs${c} in"
+ msg - " the current directory. This file is a zsh script and can"
+ msg - " access to the following variables:"
+ msg - ""
+ msg - " \$${c_b}op_sess${c}"
+ msg - " The session provided on the command line or an empty string"
+ msg - ""
+ msg - " \$${c_b}op_dir${c}"
+ msg - " The directory provided on the command line or the current"
+ msg - " directory"
+ msg - ""
+ msg - " \$${c_b}op_file${c}"
+ msg - " The file provided on the command line or an empty string"
+ msg - ""
+ msg - " The following variables can be set to modify the behaviour:"
+ msg - ""
+ msg - " ${c_b}session${c}=${c_u}SESSION${c}"
+ msg - " Use kate session named ${c_u}SESSION${c}, this can be changed"
+ msg - " on the command line"
+ msg - " Default value: \$op_sess"
+ msg - ""
+ msg - " ${c_b}dir${c}=(${c_u}DIR${c} ... )"
+ msg - " Use directories ${c_u}DIR${c} to search for files"
+ msg - " Default value: (\$op_dir)"
+ msg - ""
+ msg - " ${c_b}find_opts${c}=(${c_u}OPTIONS${c} ... )"
+ msg - " Use the options ${c_u}OPTIONS${c} for the find command line"
+ msg - " Default value: (-name \$op_file)"
+ msg - ""
+ msg - " ${c_b}command_name${c}=${c_u}COMMAND${c}"
+ msg - " The name of the kate executable"
+ msg - " Default value: kate"
+ msg - ""
+ msg - " ${c_b}command_opts${c}=(${c_u}OPTIONS${c} ... )"
+ msg - " Use the options ${c_u}OPTIONS${c} for the kate command line"
+ msg - " Default value: (-u)"
+ msg - ""
+ msg - " The function ${c_b}search${c} can be redefined. It must print"
+ msg - " one file per line to open"
+ msg - ""
+ exit $exit_status
+fi
+
+exec 3>&1
+search(){
+ for d in $dir; do
+ #$msg_l find $d $find_opts
+ find $d $find_opts
+ done
+}
+
+run(){
+ $command_name $command_opts $@ >/dev/null 2>&1 &
+}
+
+# variables that can be used in .Kprefs
+session=$op_sess
+dir=($op_dir)
+find_opts=(-name $op_file)
+if $op_grep; then
+ command_name=grep
+ command_opts=(-n $op_grep_pattern)
+ use_xargs=true
+elif $op_egrep; then
+ command_name=egrep
+ command_opts=(-n $op_grep_pattern)
+ use_xargs=true
+else
+ command_name=kate
+ command_opts=(-u)
+ use_xargs=false
+fi
+if [[ -f .Kprefs ]]; then
+ source .Kprefs
+fi
+
+# overide using command line options
+[[ -n $op_sess ]] && session=$op_sess
+$has_op_dir && dir=$op_dir
+
+if $op_grep || $op_egrep; then
+ op_show=false
+fi
+
+if [[ $command_name == kate ]] && [[ -n $session ]]; then
+ command_opts=($command_opts -s $session)
+ $msg_v "Session: $session"
+fi
+$msg_v "Search in: $dir"
+
+if $use_xargs; then
+
+ search | xargs $command_name $command_opts
+
+else
+
+ while read f; do
+ [[ -z $f ]] && continue
+ if $op_show; then
+ echo $f
+ else
+ $msg_v "File $f"
+ #$msg_l $command_name $command_opts $f
+ run $f
+ fi
+ done <<<"`search`"
+
+fi
+
+
+exit $exit_status
--
Lisaac scripts
More information about the Lisaac-commits
mailing list