加了好多东西……
This commit is contained in:
parent
36654b57d5
commit
4f81bcbf6d
55
files/.tmux.conf
Normal file
55
files/.tmux.conf
Normal file
@ -0,0 +1,55 @@
|
||||
set -g default-shell /bin/zsh
|
||||
|
||||
unbind C-b
|
||||
set -g prefix `
|
||||
bind ` send-prefix
|
||||
|
||||
unbind l
|
||||
|
||||
bind r source ~/.tmux.conf\; display '~/.tmux.conf sourced'
|
||||
bind c new-window -c '#{pane_current_path}'
|
||||
bind % split-window -h -c '#{pane_current_path}'
|
||||
bind '"' split-window -c '#{pane_current_path}'
|
||||
|
||||
# vim 的复制模式
|
||||
# prefix + [ 开始复制,Sapce 选定开头,Enter 选定结尾并复制,prefix + ] 粘贴
|
||||
set-window-option -g mode-keys vi
|
||||
|
||||
set -g mouse on # 开启鼠标
|
||||
set -g history-limit 50000 # 历史记录数量
|
||||
set -wg allow-rename off # 禁止活动进程修改窗口名
|
||||
set -wg automatic-rename off # 禁止自动命名新窗口
|
||||
set -g renumber-windows on # 关掉某个窗口后,编号重排
|
||||
|
||||
set -g default-terminal 'screen-256color'
|
||||
|
||||
set -g @plugin 'tmux-plugins/tpm'
|
||||
set -g @plugin 'tmux-plugins/tmux-sensible'
|
||||
set -g @plugin 'tmux-plugins/tmux-yank' # Copy to the system clipboard in tmux
|
||||
# set -g @plugin 'tmux-plugins/tmux-net-speed'
|
||||
# set -g @plugin 'tmux-plugins/tmux-cpu'
|
||||
set -g @plugin 'tmux-plugins/tmux-prefix-highlight' # Highlights when you press tmux prefix key
|
||||
|
||||
# theme (choose one: 256, dark, light, base16)
|
||||
set -g @plugin 'seebi/tmux-colors-solarized'
|
||||
set -g @colors-solarized 'dark'
|
||||
|
||||
set -g status-interval 1 # 状态栏刷新时间
|
||||
set -g status-right-length 120 # 状态栏右侧长度
|
||||
# set -g @net_speed_format 'D:%9s U:%9s'
|
||||
# set -g @cpu_percentage_format '%5.1f%%'
|
||||
# set -g status-right 'CPU: #{cpu_percentage} MEM: #(/usr/local/bin/tmux-mem --format " :percent") #{net_speed} #{prefix_highlight} %a %m/%d %H:%M'
|
||||
set -g status-right '#{prefix_highlight} %a %m/%d %H:%M'
|
||||
|
||||
# prefix highlight
|
||||
set -g @prefix_highlight_fg 'white'
|
||||
set -g @prefix_highlight_bg 'blue'
|
||||
set -g @prefix_highlight_show_copy_mode 'on'
|
||||
set -g @prefix_highlight_copy_mode_attr 'fg=white,bg=blue'
|
||||
set -g @prefix_highlight_show_sync_mode 'on'
|
||||
set -g @prefix_highlight_sync_mode_attr 'fg=white,bg=blue'
|
||||
|
||||
# prefix-I: install plugins (big letter I, not i)
|
||||
# prefix-U: update plugins (big letter U, not u)
|
||||
|
||||
run '~/.tmux/plugins/tpm/tpm'
|
||||
153
files/.zshrc
Normal file
153
files/.zshrc
Normal file
@ -0,0 +1,153 @@
|
||||
# If you come from bash you might have to change your $PATH.
|
||||
# export PATH=$HOME/bin:/usr/local/bin:$PATH
|
||||
|
||||
# Path to your oh-my-zsh installation.
|
||||
export ZSH=$HOME/.oh-my-zsh
|
||||
|
||||
# Set name of the theme to load --- if set to "random", it will
|
||||
# load a random theme each time oh-my-zsh is loaded, in which case,
|
||||
# to know which specific one was loaded, run: echo $RANDOM_THEME
|
||||
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
|
||||
ZSH_THEME="ys-simple"
|
||||
|
||||
# Set list of themes to pick from when loading at random
|
||||
# Setting this variable when ZSH_THEME=random will cause zsh to load
|
||||
# a theme from this variable instead of looking in $ZSH/themes/
|
||||
# If set to an empty array, this variable will have no effect.
|
||||
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
|
||||
|
||||
# Uncomment the following line to use case-sensitive completion.
|
||||
# CASE_SENSITIVE="true"
|
||||
|
||||
# Uncomment the following line to use hyphen-insensitive completion.
|
||||
# Case-sensitive completion must be off. _ and - will be interchangeable.
|
||||
# HYPHEN_INSENSITIVE="true"
|
||||
|
||||
# Uncomment one of the following lines to change the auto-update behavior
|
||||
# zstyle ':omz:update' mode disabled # disable automatic updates
|
||||
# zstyle ':omz:update' mode auto # update automatically without asking
|
||||
zstyle ':omz:update' mode reminder # just remind me to update when it's time
|
||||
|
||||
# Uncomment the following line to change how often to auto-update (in days).
|
||||
zstyle ':omz:update' frequency 13
|
||||
|
||||
# Uncomment the following line if pasting URLs and other text is messed up.
|
||||
# DISABLE_MAGIC_FUNCTIONS="true"
|
||||
|
||||
# Uncomment the following line to disable colors in ls.
|
||||
# DISABLE_LS_COLORS="true"
|
||||
|
||||
# Uncomment the following line to disable auto-setting terminal title.
|
||||
# DISABLE_AUTO_TITLE="true"
|
||||
|
||||
# Uncomment the following line to enable command auto-correction.
|
||||
# ENABLE_CORRECTION="true"
|
||||
|
||||
# Uncomment the following line to display red dots whilst waiting for completion.
|
||||
# You can also set it to another string to have that shown instead of the default red dots.
|
||||
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
|
||||
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
|
||||
# COMPLETION_WAITING_DOTS="true"
|
||||
|
||||
# Uncomment the following line if you want to disable marking untracked files
|
||||
# under VCS as dirty. This makes repository status check for large repositories
|
||||
# much, much faster.
|
||||
# DISABLE_UNTRACKED_FILES_DIRTY="true"
|
||||
|
||||
# Uncomment the following line if you want to change the command execution time
|
||||
# stamp shown in the history command output.
|
||||
# You can set one of the optional three formats:
|
||||
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
|
||||
# or set a custom format using the strftime function format specifications,
|
||||
# see 'man strftime' for details.
|
||||
# HIST_STAMPS="mm/dd/yyyy"
|
||||
|
||||
# Would you like to use another custom folder than $ZSH/custom?
|
||||
# ZSH_CUSTOM=/path/to/new-custom-folder
|
||||
|
||||
# Which plugins would you like to load?
|
||||
# Standard plugins can be found in $ZSH/plugins/
|
||||
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
|
||||
# Example format: plugins=(rails git textmate ruby lighthouse)
|
||||
# Add wisely, as too many plugins slow down shell startup.
|
||||
plugins=(git)
|
||||
plugins+=(git-open autojump zsh-autosuggestions zsh-syntax-highlighting sudo)
|
||||
plugins+=(history encode64 docker-compose tmux)
|
||||
plugins+=(dirhistory jsontools)
|
||||
plugins+=(fzf)
|
||||
|
||||
source $ZSH/oh-my-zsh.sh
|
||||
|
||||
# User configuration
|
||||
|
||||
# export MANPATH="/usr/local/man:$MANPATH"
|
||||
|
||||
# You may need to manually set your language environment
|
||||
# export LANG=en_US.UTF-8
|
||||
|
||||
# Preferred editor for local and remote sessions
|
||||
# if [[ -n $SSH_CONNECTION ]]; then
|
||||
# export EDITOR='vim'
|
||||
# else
|
||||
# export EDITOR='mvim'
|
||||
# fi
|
||||
|
||||
# Compilation flags
|
||||
# export ARCHFLAGS="-arch x86_64"
|
||||
|
||||
# Set personal aliases, overriding those provided by oh-my-zsh libs,
|
||||
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
|
||||
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
|
||||
# For a full list of active aliases, run `alias`.
|
||||
#
|
||||
# Example aliases
|
||||
# alias zshconfig="mate ~/.zshrc"
|
||||
# alias ohmyzsh="mate ~/.oh-my-zsh"
|
||||
|
||||
# ====================================================================================================
|
||||
|
||||
HIST_STAMPS='yyyy-mm-dd'
|
||||
DISABLE_AUTO_TITLE='true'
|
||||
ZSH_THEME_TERM_TITLE_IDLE='%~'
|
||||
|
||||
alias -s txt='nano'
|
||||
alias -s xz='tar -xvf'
|
||||
alias -s gz='tar -xzvf'
|
||||
alias -s tgz='tar -xzvf'
|
||||
alias -s zip='unzip'
|
||||
alias -s bz2='tar -xjvf'
|
||||
|
||||
alias cp='cp -i'
|
||||
alias cl='clear'
|
||||
|
||||
command_exists() { command -v "$@" >/dev/null 2>&1; }
|
||||
|
||||
command_exists trash-put && alias rm='trash-put'
|
||||
command_exists batcat && alias cat='batcat'
|
||||
command_exists fdfind && alias fd='fdfind'
|
||||
|
||||
if command_exists exa; then
|
||||
alias e='exa -la'
|
||||
alias et='exa -lT'
|
||||
alias ef='exa -lTa -BhHigSmu'
|
||||
fi
|
||||
|
||||
_systemctl_unit_state() {
|
||||
typeset -gA _sys_unit_state
|
||||
_sys_unit_state=( $(__systemctl list-unit-files '$PREFIX*' | awk '{print $1, $2}') )
|
||||
}
|
||||
|
||||
# pip3
|
||||
export PATH=$HOME/.local/bin:$PATH
|
||||
|
||||
# Docker
|
||||
# export DOCKER_HOST=unix:///run/user/500/docker.sock
|
||||
# export DOCKER_HOST=unix:///run/user/1000/docker.sock
|
||||
|
||||
# Yarn
|
||||
# export PATH=$PATH:$HOME/.yarn/bin
|
||||
|
||||
# Golang
|
||||
# export PATH=$PATH:/usr/local/go/bin
|
||||
# export PATH=$PATH:$HOME/.local/go/bin
|
||||
# export GOPROXY=https://goproxy.io,direct
|
||||
549
files/install-ohmyzsh.sh
Executable file
549
files/install-ohmyzsh.sh
Executable file
@ -0,0 +1,549 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script should be run via curl:
|
||||
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
||||
# or via wget:
|
||||
# sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
||||
# or via fetch:
|
||||
# sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
||||
#
|
||||
# As an alternative, you can first download the install script and run it afterwards:
|
||||
# wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
|
||||
# sh install.sh
|
||||
#
|
||||
# You can tweak the install behavior by setting variables when running the script. For
|
||||
# example, to change the path to the Oh My Zsh repository:
|
||||
# ZSH=~/.zsh sh install.sh
|
||||
#
|
||||
# Respects the following environment variables:
|
||||
# ZDOTDIR - path to Zsh dotfiles directory (default: unset). See [1][2]
|
||||
# [1] https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-ZDOTDIR
|
||||
# [2] https://zsh.sourceforge.io/Doc/Release/Files.html#index-ZDOTDIR_002c-use-of
|
||||
# ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh)
|
||||
# REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh)
|
||||
# REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS)
|
||||
# BRANCH - branch to check out immediately after install (default: master)
|
||||
#
|
||||
# Other options:
|
||||
# CHSH - 'no' means the installer will not change the default shell (default: yes)
|
||||
# RUNZSH - 'no' means the installer will not run zsh after the install (default: yes)
|
||||
# KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no)
|
||||
#
|
||||
# You can also pass some arguments to the install script to set some these options:
|
||||
# --skip-chsh: has the same behavior as setting CHSH to 'no'
|
||||
# --unattended: sets both CHSH and RUNZSH to 'no'
|
||||
# --keep-zshrc: sets KEEP_ZSHRC to 'yes'
|
||||
# For example:
|
||||
# sh install.sh --unattended
|
||||
# or:
|
||||
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
|
||||
#
|
||||
set -e
|
||||
|
||||
# Make sure important variables exist if not already defined
|
||||
#
|
||||
# $USER is defined by login(1) which is not always executed (e.g. containers)
|
||||
# POSIX: https://pubs.opengroup.org/onlinepubs/009695299/utilities/id.html
|
||||
USER=${USER:-$(id -u -n)}
|
||||
# $HOME is defined at the time of login, but it could be unset. If it is unset,
|
||||
# a tilde by itself (~) will not be expanded to the current user's home directory.
|
||||
# POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03
|
||||
HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}"
|
||||
# macOS does not have getent, but this works even if $HOME is unset
|
||||
HOME="${HOME:-$(eval echo ~$USER)}"
|
||||
|
||||
|
||||
# Track if $ZSH was provided
|
||||
custom_zsh=${ZSH:+yes}
|
||||
|
||||
# Use $zdot to keep track of where the directory is for zsh dotfiles
|
||||
# To check if $ZDOTDIR was provided, explicitly check for $ZDOTDIR
|
||||
zdot="${ZDOTDIR:-$HOME}"
|
||||
|
||||
# Default value for $ZSH
|
||||
# a) if $ZDOTDIR is supplied and not $HOME: $ZDOTDIR/ohmyzsh
|
||||
# b) otherwise, $HOME/.oh-my-zsh
|
||||
[ "$ZDOTDIR" = "$HOME" ] || ZSH="${ZSH:-${ZDOTDIR:+$ZDOTDIR/ohmyzsh}}"
|
||||
ZSH="${ZSH:-$HOME/.oh-my-zsh}"
|
||||
|
||||
# Default settings
|
||||
REPO=${REPO:-ohmyzsh/ohmyzsh}
|
||||
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
|
||||
BRANCH=${BRANCH:-master}
|
||||
|
||||
# Other options
|
||||
CHSH=${CHSH:-yes}
|
||||
RUNZSH=${RUNZSH:-yes}
|
||||
KEEP_ZSHRC=${KEEP_ZSHRC:-no}
|
||||
|
||||
|
||||
command_exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
user_can_sudo() {
|
||||
# Check if sudo is installed
|
||||
command_exists sudo || return 1
|
||||
# Termux can't run sudo, so we can detect it and exit the function early.
|
||||
case "$PREFIX" in
|
||||
*com.termux*) return 1 ;;
|
||||
esac
|
||||
# The following command has 3 parts:
|
||||
#
|
||||
# 1. Run `sudo` with `-v`. Does the following:
|
||||
# • with privilege: asks for a password immediately.
|
||||
# • without privilege: exits with error code 1 and prints the message:
|
||||
# Sorry, user <username> may not run sudo on <hostname>
|
||||
#
|
||||
# 2. Pass `-n` to `sudo` to tell it to not ask for a password. If the
|
||||
# password is not required, the command will finish with exit code 0.
|
||||
# If one is required, sudo will exit with error code 1 and print the
|
||||
# message:
|
||||
# sudo: a password is required
|
||||
#
|
||||
# 3. Check for the words "may not run sudo" in the output to really tell
|
||||
# whether the user has privileges or not. For that we have to make sure
|
||||
# to run `sudo` in the default locale (with `LANG=`) so that the message
|
||||
# stays consistent regardless of the user's locale.
|
||||
#
|
||||
! LANG= sudo -n -v 2>&1 | grep -q "may not run sudo"
|
||||
}
|
||||
|
||||
# The [ -t 1 ] check only works when the function is not called from
|
||||
# a subshell (like in `$(...)` or `(...)`, so this hack redefines the
|
||||
# function at the top level to always return false when stdout is not
|
||||
# a tty.
|
||||
if [ -t 1 ]; then
|
||||
is_tty() {
|
||||
true
|
||||
}
|
||||
else
|
||||
is_tty() {
|
||||
false
|
||||
}
|
||||
fi
|
||||
|
||||
# This function uses the logic from supports-hyperlinks[1][2], which is
|
||||
# made by Kat Marchán (@zkat) and licensed under the Apache License 2.0.
|
||||
# [1] https://github.com/zkat/supports-hyperlinks
|
||||
# [2] https://crates.io/crates/supports-hyperlinks
|
||||
#
|
||||
# Copyright (c) 2021 Kat Marchán
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
supports_hyperlinks() {
|
||||
# $FORCE_HYPERLINK must be set and be non-zero (this acts as a logic bypass)
|
||||
if [ -n "$FORCE_HYPERLINK" ]; then
|
||||
[ "$FORCE_HYPERLINK" != 0 ]
|
||||
return $?
|
||||
fi
|
||||
|
||||
# If stdout is not a tty, it doesn't support hyperlinks
|
||||
is_tty || return 1
|
||||
|
||||
# DomTerm terminal emulator (domterm.org)
|
||||
if [ -n "$DOMTERM" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc)
|
||||
if [ -n "$VTE_VERSION" ]; then
|
||||
[ $VTE_VERSION -ge 5000 ]
|
||||
return $?
|
||||
fi
|
||||
|
||||
# If $TERM_PROGRAM is set, these terminals support hyperlinks
|
||||
case "$TERM_PROGRAM" in
|
||||
Hyper|iTerm.app|terminology|WezTerm) return 0 ;;
|
||||
esac
|
||||
|
||||
# kitty supports hyperlinks
|
||||
if [ "$TERM" = xterm-kitty ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Windows Terminal also supports hyperlinks
|
||||
if [ -n "$WT_SESSION" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Konsole supports hyperlinks, but it's an opt-in setting that can't be detected
|
||||
# https://github.com/ohmyzsh/ohmyzsh/issues/10964
|
||||
# if [ -n "$KONSOLE_VERSION" ]; then
|
||||
# return 0
|
||||
# fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Adapted from code and information by Anton Kochkov (@XVilka)
|
||||
# Source: https://gist.github.com/XVilka/8346728
|
||||
supports_truecolor() {
|
||||
case "$COLORTERM" in
|
||||
truecolor|24bit) return 0 ;;
|
||||
esac
|
||||
|
||||
case "$TERM" in
|
||||
iterm |\
|
||||
tmux-truecolor |\
|
||||
linux-truecolor |\
|
||||
xterm-truecolor |\
|
||||
screen-truecolor) return 0 ;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
fmt_link() {
|
||||
# $1: text, $2: url, $3: fallback mode
|
||||
if supports_hyperlinks; then
|
||||
printf '\033]8;;%s\033\\%s\033]8;;\033\\\n' "$2" "$1"
|
||||
return
|
||||
fi
|
||||
|
||||
case "$3" in
|
||||
--text) printf '%s\n' "$1" ;;
|
||||
--url|*) fmt_underline "$2" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
fmt_underline() {
|
||||
is_tty && printf '\033[4m%s\033[24m\n' "$*" || printf '%s\n' "$*"
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2016 # backtick in single-quote
|
||||
fmt_code() {
|
||||
is_tty && printf '`\033[2m%s\033[22m`\n' "$*" || printf '`%s`\n' "$*"
|
||||
}
|
||||
|
||||
fmt_error() {
|
||||
printf '%sError: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "$FMT_RESET" >&2
|
||||
}
|
||||
|
||||
setup_color() {
|
||||
# Only use colors if connected to a terminal
|
||||
if ! is_tty; then
|
||||
FMT_RAINBOW=""
|
||||
FMT_RED=""
|
||||
FMT_GREEN=""
|
||||
FMT_YELLOW=""
|
||||
FMT_BLUE=""
|
||||
FMT_BOLD=""
|
||||
FMT_RESET=""
|
||||
return
|
||||
fi
|
||||
|
||||
if supports_truecolor; then
|
||||
FMT_RAINBOW="
|
||||
$(printf '\033[38;2;255;0;0m')
|
||||
$(printf '\033[38;2;255;97;0m')
|
||||
$(printf '\033[38;2;247;255;0m')
|
||||
$(printf '\033[38;2;0;255;30m')
|
||||
$(printf '\033[38;2;77;0;255m')
|
||||
$(printf '\033[38;2;168;0;255m')
|
||||
$(printf '\033[38;2;245;0;172m')
|
||||
"
|
||||
else
|
||||
FMT_RAINBOW="
|
||||
$(printf '\033[38;5;196m')
|
||||
$(printf '\033[38;5;202m')
|
||||
$(printf '\033[38;5;226m')
|
||||
$(printf '\033[38;5;082m')
|
||||
$(printf '\033[38;5;021m')
|
||||
$(printf '\033[38;5;093m')
|
||||
$(printf '\033[38;5;163m')
|
||||
"
|
||||
fi
|
||||
|
||||
FMT_RED=$(printf '\033[31m')
|
||||
FMT_GREEN=$(printf '\033[32m')
|
||||
FMT_YELLOW=$(printf '\033[33m')
|
||||
FMT_BLUE=$(printf '\033[34m')
|
||||
FMT_BOLD=$(printf '\033[1m')
|
||||
FMT_RESET=$(printf '\033[0m')
|
||||
}
|
||||
|
||||
setup_ohmyzsh() {
|
||||
# Prevent the cloned repository from having insecure permissions. Failing to do
|
||||
# so causes compinit() calls to fail with "command not found: compdef" errors
|
||||
# for users with insecure umasks (e.g., "002", allowing group writability). Note
|
||||
# that this will be ignored under Cygwin by default, as Windows ACLs take
|
||||
# precedence over umasks except for filesystems mounted with option "noacl".
|
||||
umask g-w,o-w
|
||||
|
||||
echo "${FMT_BLUE}Cloning Oh My Zsh...${FMT_RESET}"
|
||||
|
||||
command_exists git || {
|
||||
fmt_error "git is not installed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
ostype=$(uname)
|
||||
if [ -z "${ostype%CYGWIN*}" ] && git --version | grep -Eq 'msysgit|windows'; then
|
||||
fmt_error "Windows/MSYS Git is not supported on Cygwin"
|
||||
fmt_error "Make sure the Cygwin git package is installed and is first on the \$PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Manual clone with git config options to support git < v1.7.2
|
||||
git init --quiet "$ZSH" && cd "$ZSH" \
|
||||
&& git config core.eol lf \
|
||||
&& git config core.autocrlf false \
|
||||
&& git config fsck.zeroPaddedFilemode ignore \
|
||||
&& git config fetch.fsck.zeroPaddedFilemode ignore \
|
||||
&& git config receive.fsck.zeroPaddedFilemode ignore \
|
||||
&& git config oh-my-zsh.remote origin \
|
||||
&& git config oh-my-zsh.branch "$BRANCH" \
|
||||
&& git remote add origin "$REMOTE" \
|
||||
&& git fetch --depth=1 origin \
|
||||
&& git checkout -b "$BRANCH" "origin/$BRANCH" || {
|
||||
[ ! -d "$ZSH" ] || {
|
||||
cd -
|
||||
rm -rf "$ZSH" 2>/dev/null
|
||||
}
|
||||
fmt_error "git clone of oh-my-zsh repo failed"
|
||||
exit 1
|
||||
}
|
||||
# Exit installation directory
|
||||
cd -
|
||||
|
||||
echo
|
||||
}
|
||||
|
||||
setup_zshrc() {
|
||||
# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
|
||||
# with datestamp of installation that moved them aside, so we never actually
|
||||
# destroy a user's original zshrc
|
||||
echo "${FMT_BLUE}Looking for an existing zsh config...${FMT_RESET}"
|
||||
|
||||
# Must use this exact name so uninstall.sh can find it
|
||||
OLD_ZSHRC="$zdot/.zshrc.pre-oh-my-zsh"
|
||||
if [ -f "$zdot/.zshrc" ] || [ -h "$zdot/.zshrc" ]; then
|
||||
# Skip this if the user doesn't want to replace an existing .zshrc
|
||||
if [ "$KEEP_ZSHRC" = yes ]; then
|
||||
echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}"
|
||||
return
|
||||
fi
|
||||
if [ -e "$OLD_ZSHRC" ]; then
|
||||
OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
|
||||
if [ -e "$OLD_OLD_ZSHRC" ]; then
|
||||
fmt_error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}"
|
||||
fmt_error "re-run the installer again in a couple of seconds"
|
||||
exit 1
|
||||
fi
|
||||
mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"
|
||||
|
||||
echo "${FMT_YELLOW}Found old .zshrc.pre-oh-my-zsh." \
|
||||
"${FMT_GREEN}Backing up to ${OLD_OLD_ZSHRC}${FMT_RESET}"
|
||||
fi
|
||||
echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}"
|
||||
mv "$zdot/.zshrc" "$OLD_ZSHRC"
|
||||
fi
|
||||
|
||||
echo "${FMT_GREEN}Using the Oh My Zsh template file and adding it to $zdot/.zshrc.${FMT_RESET}"
|
||||
|
||||
# Modify $ZSH variable in .zshrc directory to use the literal $ZDOTDIR or $HOME
|
||||
omz="$ZSH"
|
||||
if [ -n "$ZDOTDIR" ] && [ "$ZDOTDIR" != "$HOME" ]; then
|
||||
omz=$(echo "$omz" | sed "s|^$ZDOTDIR/|\$ZDOTDIR/|")
|
||||
fi
|
||||
omz=$(echo "$omz" | sed "s|^$HOME/|\$HOME/|")
|
||||
|
||||
sed "s|^export ZSH=.*$|export ZSH=\"${omz}\"|" "$ZSH/templates/zshrc.zsh-template" > "$zdot/.zshrc-omztemp"
|
||||
mv -f "$zdot/.zshrc-omztemp" "$zdot/.zshrc"
|
||||
|
||||
echo
|
||||
}
|
||||
|
||||
setup_shell() {
|
||||
# Skip setup if the user wants or stdin is closed (not running interactively).
|
||||
if [ "$CHSH" = no ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# If this user's login shell is already "zsh", do not attempt to switch.
|
||||
if [ "$(basename -- "$SHELL")" = "zsh" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# If this platform doesn't provide a "chsh" command, bail out.
|
||||
if ! command_exists chsh; then
|
||||
cat <<EOF
|
||||
I can't change your shell automatically because this system does not have chsh.
|
||||
${FMT_BLUE}Please manually change your default shell to zsh${FMT_RESET}
|
||||
EOF
|
||||
return
|
||||
fi
|
||||
|
||||
echo "${FMT_BLUE}Time to change your default shell to zsh:${FMT_RESET}"
|
||||
|
||||
# Prompt for user choice on changing the default login shell
|
||||
printf '%sDo you want to change your default shell to zsh? [Y/n]%s ' \
|
||||
"$FMT_YELLOW" "$FMT_RESET"
|
||||
read -r opt
|
||||
case $opt in
|
||||
y*|Y*|"") ;;
|
||||
n*|N*) echo "Shell change skipped."; return ;;
|
||||
*) echo "Invalid choice. Shell change skipped."; return ;;
|
||||
esac
|
||||
|
||||
# Check if we're running on Termux
|
||||
case "$PREFIX" in
|
||||
*com.termux*) termux=true; zsh=zsh ;;
|
||||
*) termux=false ;;
|
||||
esac
|
||||
|
||||
if [ "$termux" != true ]; then
|
||||
# Test for the right location of the "shells" file
|
||||
if [ -f /etc/shells ]; then
|
||||
shells_file=/etc/shells
|
||||
elif [ -f /usr/share/defaults/etc/shells ]; then # Solus OS
|
||||
shells_file=/usr/share/defaults/etc/shells
|
||||
else
|
||||
fmt_error "could not find /etc/shells file. Change your default shell manually."
|
||||
return
|
||||
fi
|
||||
|
||||
# Get the path to the right zsh binary
|
||||
# 1. Use the most preceding one based on $PATH, then check that it's in the shells file
|
||||
# 2. If that fails, get a zsh path from the shells file, then check it actually exists
|
||||
if ! zsh=$(command -v zsh) || ! grep -qx "$zsh" "$shells_file"; then
|
||||
if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -n 1) || [ ! -f "$zsh" ]; then
|
||||
fmt_error "no zsh binary found or not present in '$shells_file'"
|
||||
fmt_error "change your default shell manually."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# We're going to change the default shell, so back up the current one
|
||||
if [ -n "$SHELL" ]; then
|
||||
echo "$SHELL" > "$zdot/.shell.pre-oh-my-zsh"
|
||||
else
|
||||
grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > "$zdot/.shell.pre-oh-my-zsh"
|
||||
fi
|
||||
|
||||
echo "Changing your shell to $zsh..."
|
||||
|
||||
# Check if user has sudo privileges to run `chsh` with or without `sudo`
|
||||
#
|
||||
# This allows the call to succeed without password on systems where the
|
||||
# user does not have a password but does have sudo privileges, like in
|
||||
# Google Cloud Shell.
|
||||
#
|
||||
# On systems that don't have a user with passwordless sudo, the user will
|
||||
# be prompted for the password either way, so this shouldn't cause any issues.
|
||||
#
|
||||
if user_can_sudo; then
|
||||
sudo -k chsh -s "$zsh" "$USER" # -k forces the password prompt
|
||||
else
|
||||
chsh -s "$zsh" "$USER" # run chsh normally
|
||||
fi
|
||||
|
||||
# Check if the shell change was successful
|
||||
if [ $? -ne 0 ]; then
|
||||
fmt_error "chsh command unsuccessful. Change your default shell manually."
|
||||
else
|
||||
export SHELL="$zsh"
|
||||
echo "${FMT_GREEN}Shell successfully changed to '$zsh'.${FMT_RESET}"
|
||||
fi
|
||||
|
||||
echo
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2183 # printf string has more %s than arguments ($FMT_RAINBOW expands to multiple arguments)
|
||||
print_success() {
|
||||
printf '%s %s__ %s %s %s %s %s__ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||
printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||
printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||
printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $FMT_RAINBOW $FMT_RESET
|
||||
printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||
printf '%s %s %s %s /____/ %s %s %s %s....is now installed!%s\n' $FMT_RAINBOW $FMT_GREEN $FMT_RESET
|
||||
printf '\n'
|
||||
printf '\n'
|
||||
printf "%s %s %s\n" "Before you scream ${FMT_BOLD}${FMT_YELLOW}Oh My Zsh!${FMT_RESET} look over the" \
|
||||
"$(fmt_code "$(fmt_link ".zshrc" "file://$zdot/.zshrc" --text)")" \
|
||||
"file to select plugins, themes, and options."
|
||||
printf '\n'
|
||||
printf '%s\n' "• Follow us on Twitter: $(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)"
|
||||
printf '%s\n' "• Join our Discord community: $(fmt_link "Discord server" https://discord.gg/ohmyzsh)"
|
||||
printf '%s\n' "• Get stickers, t-shirts, coffee mugs and more: $(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)"
|
||||
printf '%s\n' $FMT_RESET
|
||||
}
|
||||
|
||||
main() {
|
||||
# Run as unattended if stdin is not a tty
|
||||
if [ ! -t 0 ]; then
|
||||
RUNZSH=no
|
||||
CHSH=no
|
||||
fi
|
||||
|
||||
# Parse arguments
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--unattended) RUNZSH=no; CHSH=no ;;
|
||||
--skip-chsh) CHSH=no ;;
|
||||
--keep-zshrc) KEEP_ZSHRC=yes ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
setup_color
|
||||
|
||||
if ! command_exists zsh; then
|
||||
echo "${FMT_YELLOW}Zsh is not installed.${FMT_RESET} Please install zsh first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# if [ -d "$ZSH" ]; then
|
||||
# echo "${FMT_YELLOW}The \$ZSH folder already exists ($ZSH).${FMT_RESET}"
|
||||
# if [ "$custom_zsh" = yes ]; then
|
||||
# cat <<EOF
|
||||
|
||||
# You ran the installer with the \$ZSH setting or the \$ZSH variable is
|
||||
# exported. You have 3 options:
|
||||
|
||||
# 1. Unset the ZSH variable when calling the installer:
|
||||
# $(fmt_code "ZSH= sh install.sh")
|
||||
# 2. Install Oh My Zsh to a directory that doesn't exist yet:
|
||||
# $(fmt_code "ZSH=path/to/new/ohmyzsh/folder sh install.sh")
|
||||
# 3. (Caution) If the folder doesn't contain important information,
|
||||
# you can just remove it with $(fmt_code "rm -r $ZSH")
|
||||
|
||||
# EOF
|
||||
# else
|
||||
# echo "You'll need to remove it if you want to reinstall."
|
||||
# fi
|
||||
# exit 1
|
||||
# fi
|
||||
|
||||
# Create ZDOTDIR folder structure if it doesn't exist
|
||||
if [ -n "$ZDOTDIR" ]; then
|
||||
mkdir -p "$ZDOTDIR"
|
||||
fi
|
||||
|
||||
# setup_ohmyzsh
|
||||
setup_zshrc
|
||||
setup_shell
|
||||
|
||||
print_success
|
||||
|
||||
if [ $RUNZSH = no ]; then
|
||||
echo "${FMT_YELLOW}Run zsh to try it out.${FMT_RESET}"
|
||||
exit
|
||||
fi
|
||||
|
||||
exec zsh -l
|
||||
}
|
||||
|
||||
main "$@"
|
||||
92
files/ys-simple.zsh-theme
Normal file
92
files/ys-simple.zsh-theme
Normal file
@ -0,0 +1,92 @@
|
||||
# Clean, simple, compatible and meaningful.
|
||||
# Tested on Linux, Unix and Windows under ANSI colors.
|
||||
# It is recommended to use with a dark background.
|
||||
# Colors: black, red, green, yellow, *blue, magenta, cyan, and white.
|
||||
#
|
||||
# Mar 2013 Yad Smood
|
||||
|
||||
# VCS
|
||||
YS_VCS_PROMPT_PREFIX1=" %{$reset_color%}on%{$fg[blue]%} "
|
||||
YS_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}"
|
||||
YS_VCS_PROMPT_SUFFIX="%{$reset_color%}"
|
||||
YS_VCS_PROMPT_DIRTY=" %{$fg[red]%}x"
|
||||
YS_VCS_PROMPT_CLEAN=" %{$fg[green]%}o"
|
||||
|
||||
# Git info
|
||||
local git_info='$(git_prompt_info)'
|
||||
ZSH_THEME_GIT_PROMPT_PREFIX="${YS_VCS_PROMPT_PREFIX1}git${YS_VCS_PROMPT_PREFIX2}"
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX"
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY"
|
||||
ZSH_THEME_GIT_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN"
|
||||
|
||||
# SVN info
|
||||
local svn_info='$(svn_prompt_info)'
|
||||
ZSH_THEME_SVN_PROMPT_PREFIX="${YS_VCS_PROMPT_PREFIX1}svn${YS_VCS_PROMPT_PREFIX2}"
|
||||
ZSH_THEME_SVN_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX"
|
||||
ZSH_THEME_SVN_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY"
|
||||
ZSH_THEME_SVN_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN"
|
||||
|
||||
# HG info
|
||||
local hg_info='$(ys_hg_prompt_info)'
|
||||
ys_hg_prompt_info() {
|
||||
# make sure this is a hg dir
|
||||
if [ -d '.hg' ]; then
|
||||
echo -n "${YS_VCS_PROMPT_PREFIX1}hg${YS_VCS_PROMPT_PREFIX2}"
|
||||
echo -n $(hg branch 2>/dev/null)
|
||||
if [[ "$(hg config oh-my-zsh.hide-dirty 2>/dev/null)" != "1" ]]; then
|
||||
if [ -n "$(hg status 2>/dev/null)" ]; then
|
||||
echo -n "$YS_VCS_PROMPT_DIRTY"
|
||||
else
|
||||
echo -n "$YS_VCS_PROMPT_CLEAN"
|
||||
fi
|
||||
fi
|
||||
echo -n "$YS_VCS_PROMPT_SUFFIX"
|
||||
fi
|
||||
}
|
||||
|
||||
# Virtualenv
|
||||
local venv_info='$(virtenv_prompt)'
|
||||
YS_THEME_VIRTUALENV_PROMPT_PREFIX=" %{$fg[green]%}"
|
||||
YS_THEME_VIRTUALENV_PROMPT_SUFFIX=" %{$reset_color%}%"
|
||||
virtenv_prompt() {
|
||||
[[ -n "${VIRTUAL_ENV:-}" ]] || return
|
||||
echo "${YS_THEME_VIRTUALENV_PROMPT_PREFIX}${VIRTUAL_ENV:t}${YS_THEME_VIRTUALENV_PROMPT_SUFFIX}"
|
||||
}
|
||||
|
||||
local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%})"
|
||||
|
||||
# Prompt format:
|
||||
#
|
||||
# PRIVILEGES USER @ MACHINE in DIRECTORY on git:BRANCH STATE [TIME] C:LAST_EXIT_CODE
|
||||
# $ COMMAND
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] C:0
|
||||
# $
|
||||
|
||||
# PROMPT="
|
||||
# %{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \
|
||||
# %(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n) \
|
||||
# %{$reset_color%}@ \
|
||||
# %{$fg[green]%}%m \
|
||||
# %{$reset_color%}in \
|
||||
# %{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\
|
||||
# ${hg_info}\
|
||||
# ${git_info}\
|
||||
# ${svn_info}\
|
||||
# ${venv_info}\
|
||||
# \
|
||||
# [%*] $exit_code
|
||||
# %{$terminfo[bold]$fg[red]%}$ %{$reset_color%}"
|
||||
|
||||
PROMPT="
|
||||
%{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \
|
||||
%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\
|
||||
${hg_info}\
|
||||
${git_info}\
|
||||
${svn_info}\
|
||||
${venv_info}\
|
||||
\
|
||||
[%*] $exit_code
|
||||
%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}"
|
||||
44
init_root.sh
44
init_root.sh
@ -3,6 +3,19 @@
|
||||
scriptdir=$(dirname $(realpath $0))
|
||||
tempdir="/tmp"
|
||||
|
||||
# ============================================================
|
||||
|
||||
git_clone() {
|
||||
local repo=$1
|
||||
local dir=$2
|
||||
|
||||
if [ ! -d "$dir" ]; then
|
||||
git clone --single-branch --recursive "$github/$repo" $dir
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
|
||||
check_google_access() {
|
||||
abroad=0
|
||||
local response=$(curl -s -o /dev/null -w "%{http_code}" -m 5 "http://www.google.com")
|
||||
@ -42,7 +55,7 @@ configure_nano() {
|
||||
|
||||
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
||||
apt install nano -y
|
||||
cp $scriptdir/files/nanorc ~/.nanorc
|
||||
cp $scriptdir/files/.nanorc ~/.nanorc
|
||||
fi
|
||||
}
|
||||
|
||||
@ -68,9 +81,31 @@ configure_zsh() {
|
||||
|
||||
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
||||
apt install zsh -y
|
||||
# touch -p ~/.ssh
|
||||
# read -p "sshkey 的名字: " sshkeyname
|
||||
# ssh-keygen -t ed25519 -C $sshkeyname
|
||||
git_clone ohmyzsh/ohmyzsh ~/.oh-my-zsh
|
||||
RUNZSH=no ZSH=~/.oh-my-zsh $scriptdir/files/install-ohmyzsh.sh
|
||||
|
||||
git_clone zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions
|
||||
git_clone zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/plugins/zsh-syntax-highlighting
|
||||
git_clone paulirish/git-open ~/.oh-my-zsh/plugins/git-open
|
||||
apt install autojump -y
|
||||
|
||||
cp $scriptdir/files/.zshrc ~/.zshrc
|
||||
cp $scriptdir/files/ys-simple.zsh-theme ~/.oh-my-zsh/themes/ys-simple.zsh-theme
|
||||
fi
|
||||
}
|
||||
|
||||
configure_tmux() {
|
||||
read -p "要配置 tmux 吗?[Y/n]: " response
|
||||
|
||||
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
||||
apt install tmux -y
|
||||
git_clone tmux-plugins/tpm ~/.tmux/plugins/tpm
|
||||
git_clone tmux-plugins/tmux-sensible ~/.tmux/plugins/tmux-sensible
|
||||
git_clone tmux-plugins/tmux-yank ~/.tmux/plugins/tmux-yank
|
||||
git_clone tmux-plugins/tmux-prefix-highlight ~/.tmux/plugins/tmux-prefix-highlight
|
||||
git_clone seebi/tmux-colors-solarized ~/.tmux/plugins/tmux-colors-solarized
|
||||
cp $scriptdir/files/.tmux.conf ~/.tmux.conf
|
||||
apt install xsel -y # 能够让 tmux 剪切板与 terminal 同步
|
||||
fi
|
||||
}
|
||||
|
||||
@ -80,3 +115,4 @@ configure_ssh_keygen
|
||||
configure_nano
|
||||
configure_install_bin
|
||||
configure_zsh
|
||||
configure_tmux
|
||||
|
||||
Loading…
Reference in New Issue
Block a user