Untitled

 avatar
4ae4d
plain_text
19 days ago
5.3 kB
4
Indexable
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=100000
SAVEHIST=100000
setopt autocd extendedglob notify
unsetopt beep nomatch
bindkey -v
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall
zstyle :compinstall filename '/home/sigma.sbrf.ru@23433948/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall

export TERMINAL=ghostty
export TERM=xterm-256color
export PATH=$(print -l "$PATH":/home/work/[email protected]/.local/bin | tr ':' '\n' | awk '!seen[$0]++' | tr '\n' ':' | sed 's/:*$//')

cd() {
    if [[ $# -eq 0 ]]; then
        builtin cd ~ || return
    else
        builtin cd "$@" || return
    fi
    ls --color=auto -a
}

cds() {
    [[ $# -eq 0 ]] && builtin cd ~ || builtin cd "$@"
}

getlast() {
    emulate -L zsh -o pipefail
    {
        local _cs_was_missing=0
        if ! typeset -f _compress_spaces >/dev/null 2>&1; then
            _cs_was_missing=1
            _compress_spaces() {
                awk '{
                    in_quote = 0
                    current_quote = ""
                    result = ""
                    for (i = 1; i <= length($0); i++) {
                        char = substr($0, i, 1)

                        if (char == "\042" || char == "\047" || char == "\140") {
                            if (!in_quote) {
                                in_quote = 1
                                current_quote = char
                            } else if (char == current_quote) {
                                in_quote = 0
                                current_quote = ""
                            }
                        }

                        if (!in_quote && char ~ /[[:space:]]/)
                            if (substr(result, length(result), 1) ~ /[[:space:]]/)
                                continue
                        result = result char
                    }
                    print result
                }'
            }
        fi

        if [[ $1 == "--help" || $1 == "-h" ]]; then
            cat <<'EOF'
usage: getlast <PATTERN> [LINES]
       getlast --help | -h

Shows the last [LINES] unique commands from history containing <PATTERN>.
- Excludes duplicate entries and 'getlast' commands.
- Respects quoted text when compressing spaces.
- Requires 'grep' and 'head' installed.
- Note: does not handle escaped quotes.

Examples:
  getlast python          # last command containing "python"
  getlast docker 5        # last 5 commands containing "docker"

EOF
            return 0
        fi

        local -i correct=1
        local lines="${2:-1}"
        local pattern="${1:-.}"

        [[ $lines =~ ^[0-9]+$ ]] || correct=0
        [[ $# -le 2 ]]           || correct=0
        [[ $# -ge 1 ]]           || correct=0
        [[ -n "$1" ]]            || correct=0

        if (( correct == 1 )); then
            fc -lnr 1 \
                | grep --color=auto -- "$pattern" \
                | grep --color=auto -v "getlast" \
                | awk '!seen[$0]++' \
                | head -n "$lines" \
                | sed -E 's/\\\\n//g' \
                | _compress_spaces \
                | sed -E 's/ $//g' \
                | sed -E 's/\\n$//g' \
                | sed -E 's/ \\ / /g' \
                | grep --color=auto -- "$pattern"
        else
            echo "usage: getlast <PATTERN> [LINES]"
            echo "       getlast --help | -h"
            echo "make sure u have \"grep\" and \"head\" installed"
            return 1
        fi
    } always {
        (( _cs_was_missing )) && unfunction _compress_spaces 2>/dev/null
    }
}

alias gnome-terminal='ghostty'
alias x-terminal-emulator='ghostty'
alias ls='ls -a --color=auto'
alias grep='grep --color=auto -I --exclude-dir=__pycache__ --exclude-dir=.git --exclude-dir=.tmp_ruff_venv'
alias clip='gpaste-client add --raw'
gf() {
  local use_null=0

  # Optional: read NUL-delimited filenames from stdin
  if [[ "${1:-}" == "-0" || "${1:-}" == "--null" ]]; then
    use_null=1
    shift
  fi

  local files=()

  if (($# > 0)); then
    files=("$@")
  else
    # No args — read from stdin
    if [ -t 0 ]; then
      echo "Usage: gf [-0|--null] file1 [file2 ...]  (or pipe file names to stdin)"
      return 1
    fi

    if ((use_null)); then
      local f
      while IFS= read -r -d '' f; do
        files+=("$f")
      done
    else
      local line
      while IFS= read -r line || [ -n "$line" ]; do
        # Split on whitespace (works with `tr '\n' ' '` and plain newline input)
        local f
        for f in $line; do
          files+=("$f")
        done
      done
    fi
  fi

  if ((${#files[@]} == 0)); then
    echo "Usage: gf [-0|--null] file1 [file2 ...]  (or pipe file names to stdin)"
    return 1
  fi

  local file
  for file in "${files[@]}"; do
    if [ ! -f "$file" ]; then
      echo "Error: '$file' is not a valid file" >&2
      echo "Error: '$file' is not a valid file"
      continue
    fi

    echo "--- $file ---"
    cat -- "$file"
    echo
  done
}
PROMPT='%F{black}%K{blue} %n %F{blue}%K{green}%F{black}%K{green} %m %F{green}%K{yellow}%F{black}%K{yellow} %~ %F{yellow}%f%k%(?..%K{red}%F{black} %? )%k%f'$'\n %(#.#.>) '


source /home/sigma.sbrf.ru@23433948/.local/share/zsh-plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
Editor is loading...
Leave a Comment