浏览代码

style(toolbox): use oneliner to extract and quote container name

Marc Cornellà 8 月之前
父节点
当前提交
0ffcc3b68a
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      plugins/toolbox/toolbox.plugin.zsh

+ 6 - 2
plugins/toolbox/toolbox.plugin.zsh

@@ -4,8 +4,12 @@ function toolbox_prompt_info() {
 
 function toolbox_prompt_name() {
   [[ -f /run/.containerenv ]] || return
-  local _to_print="$(cat /run/.containerenv | awk -F\" '/name/ { print$2 }')"
-  echo ${_to_print:gs/%/%%}
+
+  # This command reads the /run/.containerenv file line by line and extracts the
+  # container name from it by looking for the `name="..."` line, and uses -F\" to
+  # split the line by double quotes. Then all % characters are replaced with %%
+  # to escape them for the prompt.
+  awk -F\" '/name/ { gsub(/%/, "%%", $2); print $2 }' /run/.containerenv
 }
 
 alias tbe="toolbox enter"