Skip to content

Commit 6f57bbe

Browse files
authored
feat(chrome): support for podman (#80)
1 parent cf318e0 commit 6f57bbe

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

fast-highlight

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ FAST_HIGHLIGHT+=(
180180
chroma-nmcli →chroma/-nmcli.ch
181181
chroma-node →chroma/-node.ch
182182
chroma-perl →chroma/-perl.ch
183+
chroma-podman →chroma/-podman.ch
183184
chroma-printf →chroma/-printf.ch
184185
chroma-ruby →chroma/-ruby.ch
185186
chroma-scp →chroma/-scp.ch

fast-syntax-highlighting.plugin.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ autoload -Uz -- is-at-least fast-theme .fast-read-ini-file .fast-run-git-command
328328
.fast-make-targets .fast-run-command .fast-zts-read-all
329329
autoload -Uz -- →chroma/-git.ch →chroma/-hub.ch →chroma/-lab.ch →chroma/-example.ch \
330330
→chroma/-grep.ch →chroma/-perl.ch →chroma/-make.ch →chroma/-awk.ch \
331-
→chroma/-vim.ch →chroma/-source.ch →chroma/-sh.ch →chroma/-docker.ch \
331+
→chroma/-vim.ch →chroma/-source.ch →chroma/-sh.ch →chroma/-docker.ch →chroma/-podman.ch \
332332
→chroma/-autoload.ch →chroma/-ssh.ch →chroma/-scp.ch →chroma/-which.ch \
333333
→chroma/-printf.ch →chroma/-ruby.ch →chroma/-whatis.ch →chroma/-alias.ch \
334334
→chroma/-subcommand.ch →chroma/-autorandr.ch →chroma/-nmcli.ch \

→chroma/-podman.ch

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
2+
# Copyright (c) 2018 Sebastian Gniazdowski
3+
#
4+
# Chroma function for command `podman'. It verifies command line, by denoting
5+
# wrong and good arguments by color. Currently implemented: verification of
6+
# image IDs passed to: podman image rm <ID>.
7+
#
8+
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
9+
# $2 - the current token, also accessible by $__arg from the above scope -
10+
# basically a private copy of $__arg
11+
# $3 - a private copy of $_start_pos, i.e. the position of the token in the
12+
# command line buffer, used to add region_highlight entry (see man),
13+
# because Zsh colorizes by *ranges* in command line buffer
14+
# $4 - a private copy of $_end_pos from the above scope
15+
#
16+
17+
(( next_word = 2 | 8192 ))
18+
19+
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
20+
local __style
21+
integer __idx1 __idx2
22+
local -a __lines_list
23+
24+
(( __first_call )) && {
25+
# Called for the first time - new command
26+
# FAST_HIGHLIGHT is used because it survives between calls, and
27+
# allows to use a single global hash only, instead of multiple
28+
# global variables
29+
FAST_HIGHLIGHT[chroma-podman-counter]=0
30+
FAST_HIGHLIGHT[chroma-podman-got-subcommand]=0
31+
FAST_HIGHLIGHT[chroma-podman-subcommand]=""
32+
FAST_HIGHLIGHT[chrome-podman-got-msg1]=0
33+
return 1
34+
} || {
35+
# Following call, i.e. not the first one
36+
37+
# Check if chroma should end – test if token is of type
38+
# "starts new command", if so pass-through – chroma ends
39+
[[ "$__arg_type" = 3 ]] && return 2
40+
41+
if (( in_redirection > 0 || this_word & 128 )) || [[ $__wrd == "<<<" ]]; then
42+
return 1
43+
fi
44+
45+
if [[ "$__wrd" = -* && ${FAST_HIGHLIGHT[chroma-podman-got-subcommand]} -eq 0 ]]; then
46+
__style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option}
47+
else
48+
if (( FAST_HIGHLIGHT[chroma-podman-got-subcommand] == 0 )); then
49+
FAST_HIGHLIGHT[chroma-podman-got-subcommand]=1
50+
FAST_HIGHLIGHT[chroma-podman-subcommand]="$__wrd"
51+
__style=${FAST_THEME_NAME}subcommand
52+
(( FAST_HIGHLIGHT[chroma-podman-counter] += 1 ))
53+
else
54+
__wrd="${__wrd//\`/x}"
55+
__arg="${__arg//\`/x}"
56+
__wrd="${(Q)__wrd}"
57+
if [[ "${FAST_HIGHLIGHT[chroma-podman-subcommand]}" = "image" ]]; then
58+
[[ "$__wrd" != -* ]] && {
59+
(( FAST_HIGHLIGHT[chroma-podman-counter] += 1, __idx1 = FAST_HIGHLIGHT[chroma-podman-counter] ))
60+
61+
if (( __idx1 == 2 )); then
62+
__style=${FAST_THEME_NAME}subcommand
63+
elif (( __idx1 == 3 )); then
64+
.fast-run-command "podman images -q" chroma-podman-list ""
65+
[[ -n "${__lines_list[(r)$__wrd]}" ]] && {
66+
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \
67+
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
68+
} || {
69+
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && \
70+
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
71+
}
72+
fi
73+
} || __style=${FAST_THEME_NAME}${${${__wrd:#--*}:+single-hyphen-option}:-double-hyphen-option}
74+
else
75+
return 1
76+
fi
77+
fi
78+
fi
79+
}
80+
81+
# Add region_highlight entry (via `reply' array)
82+
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
83+
84+
# We aren't passing-through, do obligatory things ourselves
85+
(( this_word = next_word ))
86+
_start_pos=$_end_pos
87+
88+
return 0
89+
90+
# vim:ft=zsh:et:sw=4

0 commit comments

Comments
 (0)