zsh 指定 zshrc 目录并在 .zshrc 中指定 alias

2023/12/01 zsh 共 2031 字,约 6 分钟

目录

切换到 zsh

ZDOTDIR=/home/users/double12gzh zsh && source /home/users/double12gzh/.my_path

配置 .zshrc

[root@archlinux /home/users/double12gzh]$ cat .zshrc
# Enable colors and change prompt:
autoload -U colors && colors
PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "

export PATH=/home/users/double12gzh/bin:$PATH

# History in cache directory:
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.cache/zsh/history

# Basic auto/tab complete:
autoload -U compinit
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit
_comp_options+=(globdots)               # Include hidden files.

export KEYTIMEOUT=1
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
bindkey  "^[[H"   beginning-of-line
bindkey  "^[[F"   end-of-line
bindkey  "^[[2~"  vi-insert
bindkey  "^[[3~"  delete-char
bindkey  "^A"     beginning-of-line
bindkey  "^E"     end-of-line
bindkey  "^P"     history-substring-search-up
bindkey  "^N"     history-substring-search-down
bindkey  "^R"     history-incremental-search-backward

# Edit line in vim with ctrl-e:
autoload edit-command-line; zle -N edit-command-line
bindkey '^o' edit-command-line

# Load aliases and shortcuts if existent.
[ -f "/home/users/double12gzh/.local_setup" ] && source "/home/users/double12gzh/.local_setup"

.local_setup

[root@archlinux /home/users/double12gzh]$ cat /home/users/double12gzh/.local_setup
# 使用
# 1. 切换到 zsh
# 2. source 本文件

SCRIPT_DIR=$(dirname "$(readlink -f "$0")")

export PATH="${SCRIPT_DIR}"/bin:$PATH

# >>> begin >>>
cluster_tools="${SCRIPT_DIR}/utils"
if [ -d "$cluster_tools" ]; then
    # 加载函数 get_cluster_kubectl
    source "$cluster_tools/cluster_tools.sh"

    # 创建别名
    alias cluster1="$(get_cluster_kubectl ${cluster1})"
fi
# >>> end >>>

cluster_tools.sh

#!/bin/bash

SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
PARENT_DIR="$(dirname "$(readlink -f "$SCRIPT_DIR")")"

source $PARENT_DIR/utils/color.sh

kubectl_cmd="kubectl --kubeconfig="
kubeconfig_path="${PARENT_DIR}/utils/.apiserverkubeconfig"

# 集群名称
cluster1="cluster1"

function get_cluster_kubectl() {
    cluster_name=$1

    case $cluster_name in
    "${cluster1}")
        echo "$kubectl_cmd$kubeconfig_path/${cluster1}"
        ;;
     *)
        echo ""
        ;;
    esac
}

Search

    Table of Contents