forked from nakamuray/zaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zaw-launcher.zsh: experimental script to start zaw as command
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/zsh | ||
# | ||
# zaw-launcher.zsh | ||
# | ||
# launcher script to start zaw as command | ||
|
||
# source zaw.zsh | ||
zmodload zsh/parameter | ||
local this_file="${funcsourcetrace[1]%:*}" | ||
local cur_dir="${this_file:A:h}" | ||
source "${cur_dir}/zaw.zsh" | ||
|
||
|
||
# parse arguments | ||
do_eval=0 | ||
|
||
while getopts 'eh' opt; do | ||
case "${opt}" in | ||
e) | ||
do_eval=1 | ||
;; | ||
|
||
h) | ||
print \ | ||
"Usage: $0 [options] [source name] | ||
Options: | ||
-h show this help | ||
-e eval result string | ||
" | ||
exit | ||
;; | ||
esac | ||
done | ||
|
||
if (( OPTIND > 1 )); then | ||
shift $(( OPTIND - 1 )) | ||
fi | ||
|
||
zaw_args=() | ||
if [[ $# > 0 && "${zaw_sources[$1]}" != "" ]]; then | ||
zaw_args+="${zaw_sources[$1]}" | ||
fi | ||
|
||
|
||
# use zle-line-init to start zaw right after vared | ||
function zle-line-init() { | ||
zle zaw "${(@)zaw_args}" | ||
|
||
# return from vared | ||
zle accept-line | ||
} | ||
zle -N zle-line-init | ||
|
||
vared -c cmd | ||
|
||
if (( do_eval )); then | ||
eval "${cmd}" | ||
else | ||
print "${cmd}" | ||
fi |