Skip to content
Snippets Groups Projects

shell

3 unresolved threads
Open Vladislav Gubarev requested to merge shell into main
3 unresolved threads
Compare and
3 files
+ 52
36
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 14
16
    • [auto-generated]

      Here are my comments on the provided patch:

      1. Change from printf to echo in omz_f() function:

        • Original:
          IFS=";" printf "\033[%sm" $*
        • Patch:
          IFS=";" echo "\033[%sm" $*
        • Issue: The echo command does not support format specifiers like printf. This change will break the ANSI escape codes formatting because echo will simply output the string as-is without interpreting %s.
        • Suggestion: Retain the original printf command to ensure proper ANSI escape code formatting.
          IFS=";" printf "\033[%sm" $*
      2. ZSH_COMPDUMP Path Change:

        • Original:
          ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
        • Patch:
          ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump"
        • Issue: Removing the unique identifier from the filename (${SHORT_HOST}-${ZSH_VERSION}) might cause conflicts if multiple versions of zsh are used or if the same home directory is shared among different environments.
        • Suggestion: Consider retaining at least some unique elements in the filename to avoid potential clashes.
          ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}"
      3. Modification of Metadata Construction and Comparison Logic:

        • Metadata Construction:
          • Original:
            zcompdump_revision="#omz revision: $(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)"
            zcompdump_fpath="#omz fpath: $fpath"
          • Patch:
            zcompdump_meta_lines=4
            zcompdump_meta="\
            #omz host: $SHORT_HOST
            #omz bash version: $ZSH_VERSION
            #omz revision: $(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)
            #omz fpath: $fpath"
          • Issue: The increased complexity and hardcoding the metadata lines count (zcompdump_meta_lines=4) makes the maintenance harder. Additionally, if any new metadata line is added, it would require updating this variable manually.
          • Suggestion: You can dynamically count the number of lines in zcompdump_meta instead of hardcoding it.
            zcompdump_meta_lines=$(echo "$zcompdump_meta" | wc -l)
        • Metadata Comparison:
          • Original:
            if ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null \
               || ! command grep -q -Fx "$zcompdump_fpath" "$ZSH_COMPDUMP" 2>/dev/null; then
              command rm -f "$ZSH_COMPDUMP"
              zcompdump_refresh=1
            fi
          • Patch:
            if [[ 0$(command grep -c -Fx "$zcompdump_meta" "$ZSH_COMPDUMP" 2>/dev/null) \
              -ne $zcompdump_meta_lines ]]; then
              command rm "$ZSH_COMPDUMP"
              zcompdump_refresh=1
            fi
          • Issue: This comparison logic seems overly complex since grep -c will return 0 or 1 based on whether the text is found, which should be sufficient without needing to compare line counts.
          • Suggestion: Simplify the condition to check if the entire metadata block is present.
            if ! grep -qF "$zcompdump_meta" "$ZSH_COMPDUMP" 2>/dev/null; then
              command rm -f "$ZSH_COMPDUMP"
              zcompdump_refresh=1
            fi
      4. Appending Metadata using echo:

        • Patch:
          echo "\nzcompdump_meta" >>| "$ZSH_COMPDUMP"
        • Issue: Using >>| for appending is non-standard and may not work across all shells. Also, the variable zcompdump_meta is not expanded correctly within double quotes.
        • Suggestion: Use standard redirection and properly expand the variable.
          echo -e "\n$zcompdump_meta" >> "$ZSH_COMPDUMP"
      5. Incorrect Condition for Loading Theme:

        • Original:
          if [ ! "$ZSH_THEME" = "" ]; then
        • Patch:
          if [ "$ZSH_THEME" = "" ]; then
        • Issue: The new condition is incorrect because it should load the theme when ZSH_THEME is not empty.
        • Suggestion: Revert this change back to the original.
          if [ ! "$ZSH_THEME" = "" ]; then

      Summary of Suggestions:

      1. Revert the change from printf to echo in omz_f().
      2. Retain unique identifiers (at least $SHORT_HOST) in the ZSH_COMPDUMP path.
      3. Dynamically calculate the number of lines in zcompdump_meta instead of hardcoding it.
      4. Simplify the metadata comparison logic.
      5. Correctly append metadata and use standard redirection.
      6. Ensure the condition for loading the theme checks if ZSH_THEME is not empty.

      Incorporating these changes should improve the robustness and maintainability of the script.

@@ -4,7 +4,7 @@
# 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow
omz_f() {
[ $# -gt 0 ] || return
IFS=";" printf "\033[%sm" $*
IFS=";" echo "\033[%sm" $*
}
# If stdout is not a terminal ignore all formatting
[ -t 1 ] || omz_f() { :; }
@@ -105,17 +105,21 @@ fi
# Save the location of the current completion dump file.
if [ -z "$ZSH_COMPDUMP" ]; then
ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump"
fi
# Construct zcompdump OMZ metadata
zcompdump_revision="#omz revision: $(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)"
zcompdump_fpath="#omz fpath: $fpath"
zcompdump_meta_lines=4
zcompdump_meta="\
#omz host: $SHORT_HOST
#omz bash version: $ZSH_VERSION
#omz revision: $(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)
#omz fpath: $fpath"
# Delete the zcompdump file if OMZ zcompdump metadata changed
if ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null \
|| ! command grep -q -Fx "$zcompdump_fpath" "$ZSH_COMPDUMP" 2>/dev/null; then
command rm -f "$ZSH_COMPDUMP"
if [[ 0$(command grep -c -Fx "$zcompdump_meta" "$ZSH_COMPDUMP" 2>/dev/null) \
-ne $zcompdump_meta_lines ]]; then
command rm "$ZSH_COMPDUMP"
zcompdump_refresh=1
fi
@@ -132,16 +136,10 @@ fi
# Append zcompdump metadata if missing
if (( $zcompdump_refresh )); then
# Use `tee` in case the $ZSH_COMPDUMP filename is invalid, to silence the error
# See https://github.com/ohmyzsh/ohmyzsh/commit/dd1a7269#commitcomment-39003489
tee -a "$ZSH_COMPDUMP" &>/dev/null <<EOF
$zcompdump_revision
$zcompdump_fpath
EOF
echo "\nzcompdump_meta" >>| "$ZSH_COMPDUMP"
fi
unset zcompdump_revision zcompdump_fpath zcompdump_refresh
unset zcompdump_meta zcompdump_refresh
# Load all of the config files in ~/oh-my-zsh that end in .zsh
@@ -168,7 +166,7 @@ done
unset config_file
# Load the theme
if [ ! "$ZSH_THEME" = "" ]; then
if [ "$ZSH_THEME" = "" ]; then
if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
Loading