Skip to content

Commit

Permalink
CTags improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
psprint committed May 8, 2023
1 parent 7801829 commit 7af39c8
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 50 deletions.
27 changes: 26 additions & 1 deletion AppRun
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
#!/usr/bin/env sh
#env
#tree $APPDIR
command $APPDIR/bin/n-c --ifile "$APPIMAGE" "$@"

ZERO="$0"
ZERO="${ZERO%/*}"
case $ZERO in
(/*)
;;
(*)
ZERO="$PWD/$ZERO"
;;
esac

iqgetpath() {
export INPTH=$*
REPLY=$($ZSH_CONTROL_BIN -f -c 'print -P -r -- %F{30}${INPTH:P}%f')
unset INPTH
}

: ${APPDIR:="$ZERO"}
source $APPDIR/zsh.cfg

{
iqgetpath "$ZSH_CONTROL_BIN"
printf %s\\n "Restarting with bundled Zsh (found at: ·$REPLY·)"
} 2>/dev/null

exec $ZSH_CONTROL_BIN $APPDIR/bin/n-c --ifile "$APPIMAGE" "$@"
32 changes: 5 additions & 27 deletions bin/n-c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env zsh
# Copyright (c) 2023 Sebastian Gniazdowski
#
# NC next-gen file-manager
Expand All @@ -8,32 +8,6 @@
# /bin/sh stage, load configuration to obtain $ZSH_CONTROL_BIN
#

ZERO="${0##$PWD}"
[ -z "$APPDIR" ] && APPDIR=$PWD/${ZERO%/*}
APPCFG="$APPDIR/zsh.cfg"

iqgetpath() {
export INPTH=$*
REPLY=$($ZSH_CONTROL_BIN -f -c 'print -P -r -- %F{30}${INPTH:P}%f')
unset INPTH
}

[ -f "$APPCFG" ] && . "$APPCFG"

[ -z "$ZSH_CONTROL_BIN" ] && ZSH_CONTROL_BIN="zsh"

if [ -z "$ZSH_VERSION" ]; then
args="\"$0\""
for arg; do
args="$args \"$arg\""
done
{
iqgetpath "$ZSH_CONTROL_BIN"
printf %s\\n "Restarting with bundled Zsh ($REPLY)"
} 2>/dev/null
builtin exec /usr/bin/env "${ZSH_CONTROL_BIN}" -f -c "source ${args}"
fi

n-c() {
# ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
# The only place where code repetition occurs
Expand All @@ -51,6 +25,10 @@ n-c() {
0=${${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}:A}
source $0:h:h/share/preamble.inc.zsh --fun

typeset -gx APPCFG APPDIR
: ${APPDIR:=$0:h:h} ${APPCFG:=$APPDIR/zsh.cfg}
source $APPCFG

# ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
# End of code repetition
# ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
Expand Down
5 changes: 3 additions & 2 deletions lib/zui-lib/functions/zui-list
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ trap "REPLY=-2; reply=(); return 1" TERM INT QUIT
# List was processed, check if variables aren't off range
-zui_list_verify_vars(){
integer Q
[[ $1 -ne 1 && $ZUI[CURRENT_IDX] -gt "$__last_element" ]] && ZUI[CURRENT_IDX]="$__last_element"
[[ $ZUI[CURRENT_IDX] -eq 0 && ("$__last_element" -ne 0 || $1 -ne 0) ]] && ZUI[CURRENT_IDX]=1
[[ $ZUI[IO_COUNT] -eq 0 && $ZUI[CURRENT_IDX] -gt "$__last_element" ]] && ZUI[CURRENT_IDX]="$__last_element"
[[ $ZUI[CURRENT_IDX] -eq 0 && ("$__last_element" -gt 0 && $ZUI[IO_COUNT] -eq 0) ]] && ZUI[CURRENT_IDX]=5

# Verify that element is just visible, if not then compute exact page
if [[ $ZUI[CURRENT_IDX] -lt $ZUI[FROM_WHAT_IDX_LIST_IS_SHOWN] ||
Expand Down Expand Up @@ -254,6 +254,7 @@ trap "REPLY=-2; reply=(); return 1" TERM INT QUIT
buf="${buf//(#b)$'\034'[^$'\034']#$'\034'[^$'\034']#$'\034'[^$'\034']#$'\034'[^$'\034']#$'\034'([^$'\034']#)$'\034'([^$'\034']#)$'\034'([^$'\02']#)$'\02'/${(mr:${(P)${(Q)match[1]}}:: :)${(As:;:)${(P)${(Q)match[3]}}}[${(P)${(Q)match[2]}}]}}"

-zui_list_translate_color_marks "$buf"
current_page_idx=$((current_page_idx>0?current_page_idx:1))
__disp_list2[current_page_idx]="${REPLY//$'\n'/n}" # replace newlines with "n" (3/3)
}

Expand Down
1 change: 1 addition & 0 deletions lib/zui-lib/syslib.lzui
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ function -zui_sys_add_message() {
# House-keeping
(( ${#ZUI_MESSAGES} >= ZUI[log_size] + 10 ))&&\
{ ZUI_MESSAGES=( "${(@)ZUI_MESSAGES[1+10,-1]}" ); }
true
} # }}}


Expand Down
4 changes: 2 additions & 2 deletions libexec/console
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ console(){

# find interpreter
typeset -g ZSH_CONTROL_BIN
: ${ZSH_CONTROL_BIN:=$commands[zsh]}
type $ZSH_CONTROL_BIN&>/dev/null||ZSH_CONTROL_BIN=$commands[zsh]
ZSH_CONTROL_BIN=$ZSH_CONTROL_BIN:A

# verify
if ! type $ZSH_CONTROL_BIN&>/dev/null;then
if ! type $ZSH_CONTROL_BIN&>>/dev/null;then
print -u2 Error: cannot find zsh binary, \
cannot continue...
return 1
Expand Down
78 changes: 60 additions & 18 deletions smart-consoles/iqnc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
iqnc()
{
# Preamble – emulate & 0=…
0=${${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}:A}
0=${${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}:A}

source $0:h:h/share/preamble.inc.zsh --script --fun --cleanup

Expand All @@ -30,6 +30,20 @@ iqw(){
-zui_glib_msg "${@//\{[^\}]#\}/}"
}

iqnc_mime_setup(){
zstyle ':mime:*' browser-style running x tty
zstyle ':mime:*' x-browsers google-chrome
zstyle ':mime:*' tty-browsers w3m links
zstyle :mime:browser:new:google-chrome: command %b %u
zstyle :mime:browser:running:google-chrome: command %b %u
zstyle :mime:browser:new:w3m: command %b %u
zstyle :mime:browser:running:w3m: command %b %u
zstyle :mime: mailcap $APPDIR/.mailcap ~/.mailcap /etc/mailcap
zstyle :mime: mime-types $APPDIR/.mime.types ~/.mime.types /etc/mime.types
autoload -Uz zsh-mime-setup pick-web-browser
zsh-mime-setup
}

iqnc_util_swap4(){
local Q=$1 Q0=$2
shift 0+2
Expand Down Expand Up @@ -111,7 +125,7 @@ iqnc_view_switch(){
ZUI[SEARCH_BUFFER_TAGS]\
ZUI[SEARCH_BUFFER]

buffer=$ZUI[SEARCH_BUFFER]
typeset -g buffer=$ZUI[SEARCH_BUFFER]
if ((in0==VIEW));then
ZUI[CURRENT_IDX_PVIEW_BKP$QPATH]=$ZUI[CURRENT_IDX]
elif ((in0==CQUE));then
Expand Down Expand Up @@ -303,10 +317,10 @@ cmd-page-up(){
-zui_listin_compute_first_to_show_idx
}
# Views
cmd-command-history-view(){iqnc_cmd_next 2;}
cmd-contents-view(){iqnc_cmd_next 1;}
cmd-main-view(){iqnc_cmd_next 0;}
cmd-tags-view(){iqnc_cmd_next 3;}
cmd-command-history-view(){iqnc_cmd_next $CQUE;}
cmd-contents-view(){iqnc_cmd_next $VIEW;}
cmd-main-view(){iqnc_cmd_next $CIN;}
cmd-tags-view(){iqnc_cmd_next $TAGS;}
cmd-set-view(){local -A Qe=(main 0 preview 1 hist 2 tags 3 "" 0);iqnc_cmd_next $Qe[$1];}
cmd-show-stdin(){ZUI[HAVE_0_INPUT]=1;ZUI[IO_COUNT]=33;iqnc_hub;}
# Commands
Expand All @@ -333,9 +347,9 @@ cmd-next-command(){iqnc_command_top 1;}
cmd-prev-command(){iqnc_command_top 0;}

# directories
cmd-pwd-up(){((ZUI[GEN_B_IDX]!=0))&&{iqnc_cmd_next 0;return 0;}; local PPWD=$PWD;if builtin cd -q -- $PWD:h;then iqnc_push_pwd $PPWD; iqw "Current PWD is: " "" "" $PWD(D);iqnc_cmd_next 0; else iqw "Cannot change directory to: " "" "" ..;fi;}
cmd-pwd-up(){((ZUI[GEN_B_IDX]!=$CIN))&&{iqnc_cmd_next $CIN;return 0;}; local PPWD=$PWD;if builtin cd -q -- $PWD:h;then iqnc_push_pwd $PPWD; iqw "Current PWD is: " "" "" $PWD(D);iqnc_cmd_next $CIN; else iqw "Cannot change directory to: " "" "" ..;fi;}
cmd-cd(){local Q=${(M)1:#-*};[[ $1 == -* ]]&&shift;if builtin cd -q -- "$1";then [[ $Q != -q
]]&&{iqw "PWD dir changed to: " "" "" $PWD; iqnc_cmd_next 0;};else iqw "Cannot change directory to: " "" "" $1;fi;}
]]&&{iqw "PWD dir changed to: " "" "" $PWD; iqnc_cmd_next $CIN;};else iqw "Cannot change directory to: " "" "" $1;fi;}
cmd-prev-pwd(){iqnc_pop_pwd; cmd-cd "$REPLY";}

# cursor
Expand Down Expand Up @@ -497,7 +511,6 @@ if ((!$+Opts[--refresh])); then
ZUI[cursor]=$#ZUI[QUERY_BUFFER]+1
fi
iqnc_set_prompt $ZUI[START_IN_QUERY]
ZUI[GEN_B_IDX]=0

local -a qitems iq0items q0input q0input_proc
integer Q0_SAVE_PIPE tmout
Expand All @@ -513,7 +526,7 @@ fi
zui::bindkey F9 '{print \\n cursor:$ZUI[cursor], cmdno:$ZUI[CMD_NO], query:$ZUI[IN_QUERY], qbuf: $ZUI[QUERY_BUFFER], view:$ZUI[SEARCH_BUFFER_PREVIEW], gl:$ZUI[SEARCH_BUFFER_GLOBAL], sbuff:$ZUI[SEARCH_BUFFER], current:$ZUI[CURRENT_IDX], PVIEW_Q:$ZUI[CURRENT_IDX_PVIEW_BKP_$ZUI[QPATH]], PVIEW:$ZUI[CURRENT_IDX_PVIEW_BKP], TAG:$ZUI[CURRENT_IDX_TAGS_BKP], main:$ZUI[CURRENT_IDX_MAIN_BKP] sptr:$ZUI[status_pointer]|tee -a /tmp/reply;}'
zui::bindkey F10 '{builtin source $NC_CON_DIR/iqnc --refresh||\
iqw -r "Reload finished with error: " $?;}'

zui::bindkey F14 '{builtin zcurses end;sleep 3;}'
unsetopt warncreateglobal
builtin source -- $NCCFG
setopt warncreateglobal
Expand Down Expand Up @@ -716,7 +729,7 @@ iqnc_fill_0(){
local TXT=$reply[1]
separ
#local -a q0items=("$qitems[@]")
qitems=($REPLY "s$TXT" $REPLY "$q0input_proc[@]")
qitems=($REPLY "$TXT" $REPLY "$q0input_proc[@]")
#[[ -n ${qitems:|q0items} ]]
-zui_glib_fly_array_refresh 1
fi
Expand Down Expand Up @@ -803,6 +816,7 @@ iqnc_find_tags_index() {
iqnc_fill_tags(){
ZUI[COLORING_PATTERN]="((#s)[^[:space:]]##|·[^·]##·)"
iqnc_find_tags_index || {iqw "No TAGS file in ../…"; return 1;}
qa_tag_data=(${(o)qa_tag_data})
qa=(${qa_tag_data//(#b)([^$'\177']##)$'\177'([^$'\1']##)*/${(r:39:: :)match[2]} $match[1]})
iqnc_search_prompt
separ
Expand All @@ -827,7 +841,7 @@ iqnc_fill_help(){
# Ensure cursor is visible
if ((ZUI[CURRENT_IDX]<5&&!$#ZUI[SEARCH_BUFFER]&&!ZUI[UNIQ_MODE]));then
((__last_element>=5))&&\
{ ZUI[CURRENT_IDX]=5;-zui_list_verify_vars 1;ZUI[redraw]=1;}
{ ZUI[CURRENT_IDX]=5;-zui_list_verify_vars;ZUI[redraw]=1;}
fi

ZUI[VIEW_CHANGE]=$((ZUI[VIEW_CHANGE]+${#${TM:#$ZUI[text_mode]}}))
Expand All @@ -842,8 +856,7 @@ iqnc_fill_help(){
((ZUI[VIEW_CHANGE]))||return 0
if [[ -n $ZUI[COMMAND] ]];then
local CMD=$ZUI[COMMAND]
ZUI[GEN_B_IDX]=0
iqnc_hub
iqnc_cmd_next $CIN $ZUI[GEN_B_IDX]
fi
builtin unset 'ZUI[COMMAND]'
iqnc_util_set_current_idx
Expand All @@ -860,8 +873,9 @@ if (($+Opts[--refresh])); then
fi

## Start application ##
iqnc_mime_setup
-zui_glib_msg "" "@@@ " "Welcome to " "NC System " "console!" " @@@";
integer EC
integer QFLAG EC
iqnc_hub 1 1 1
ZUI[redraw]=1
while (( 1 )); do
Expand All @@ -870,14 +884,31 @@ while (( 1 )); do
ZUI[started]=1
zui-event-loop a:qitems
builtin print -rn -- $terminfo[rmcup]$termcap[te]
QFLAG=0
# exit?
[[ -z $REPLY ]]&&break
local QFILE= REPLY_SAVE=$REPLY; integer QIDX=0
[[ $ZUI[SEARCH_BUFFER] != $~NC[WRONGSTR] ]]&&
{iqnc_create_histories; builtin print $ZUI[SEARCH_BUFFER]>>!$NCSHIST;}

if [[ $ZUI[GEN_B_IDX] = $TAGS ]];then
integer QI=0
[[ -n $ZUI[SEARCH_BUFFER] || $ZUI[UNIQ_MODE] -eq 1 ]]||QI=-4
[[ -n $ZUI[SEARCH_BUFFER] ]]&&\
repeat 1; do typeset +U -ga __slist=("$__qlist[@]");done
if [[ $ZUI[SEARCH_BUFFER] ]]&&-zui_sys_get_match_line QIDX; then
QI+=QIDX
else
QI+=ZUI[CURRENT_IDX]
fi
if [[ $qa_tag_data[QI] = (#b)[^$'\177']##$'\177'[^$'\1']##$'\1'\
([^$'\2']##)$'\2'((*)) ]];then
QFILE=$match[3] QIDX=${match[1]%%,*} QFLAG=1
fi
fi

# …from diff?
if [[ -z $ZUI[SEARCH_BUFFER] ]];then
if [[ $QFLAG -eq 0 && -z $ZUI[SEARCH_BUFFER] ]];then
# …from preview?
if ((ZUI[GEN_B_IDX]%VIEWS==VIEW));then
QFILE=$ZUI[QPATH]
Expand All @@ -888,7 +919,7 @@ while (( 1 )); do
QFILE=$REPLY_SAVE
fi
# search selection?
else
elif [[ $QFLAG -eq 0 ]];then
# prepare the list var that's needed by -zui_sys_get_match_line
repeat 1; do typeset +U -ga __slist=("$__qlist[@]");done
if -zui_sys_get_match_line QIDX; then
Expand Down Expand Up @@ -950,14 +981,24 @@ while (( 1 )); do
"\$VISUAL (=$VISUAL) " then "" " \$EDITOR (=$EDITOR)"
fi
# Run the editor in $REPLY, first cd-ing into project's directory
[[ -n $REPLY ]]&&\
if [[ -n $REPLY && $(file -- $QFILE) = (#i)*text* ]];then
int/nc::run-command -C $PWD \
"$REPLY" ${${QIDX:#0##}:++$QIDX} -- $QFILE
else
local QTMP=${zsh_mime_handlers[$QFILE:e]// (\"|)%?(\"|)/}
[[ -n $saliases[$QFILE:e] && -n $QTMP ]]&&\
iqw "MIME type " $QFILE:e " program run: " "\`$QTMP\`"||\
iqw "No MIME program for extension: " "" ".$QFILE:e"\
" you can set it via " "~/.mailcap" " and in" \
" ~/.mime-types"
eval ./$QFILE
fi
EC+=$? QFLAG=1
fi
if [[ -d **/$QFILE(#qNY1/) ]];then
[[ -d $QFILE ]]||{QFILE=(**/$QFILE(#qNY1/));QFILE=$QFILE[1];}
iqw "Changing directory to: " ${QFILE##$PWD/}
cmd-push-screen
iqnc_push_pwd
if builtin cd -q -- $QFILE;then
iqnc_get_command
Expand All @@ -968,6 +1009,7 @@ while (( 1 )); do
fi
QFLAG=1
fi

if ((!QFLAG));then
iqw "" "" "" "NO SUCH FILE OR DIRECTORY: " $QFILE
else
Expand Down

0 comments on commit 7af39c8

Please sign in to comment.