1683

· 👁 19 views

...and another useful #bash #alias to #remove the text inside single #quotes by esc-k:

# Clear the content between single quotes while preserving the quotes
clear_inside_quotes() {
  local line="${READLINE_LINE}"

  # Only run if the line contains at least two single quotes
  if [[ "${line}" == *"'"*"'"* ]]; then

    # prefix: everything before the first quote
    local prefix="${line%%\'*}"

    # suffix: everything after the last quote
    local suffix="${line##*\'}"

    # Reconstruct the line with empty quotes
    READLINE_LINE="${prefix}''${suffix}"

    # Move the cursor back inside the empty quotes
    READLINE_POINT=$((${#prefix} + 1))
  fi
}
# Bind the function to Alt-k (Escape + k)
bind -x '"\ek": clear_inside_quotes'