From 1077d86641def34b5115d4dacd0fc742e8e58d82 Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 8 May 2022 12:07:27 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=BA=20Refactor=20dotfiles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .alias_docker | 14 -- .alias_git | 12 -- .alias_middleware | 49 ----- .aliases | 69 ------ .bash_alias | 199 ++++++++++++++++++ .bash_bin | 199 ++++++++++++++++++ .bash_darwin | 28 +++ .alias_k8s => .bash_k8s | 25 ++- .centos7 => .bash_linuxgnu | 16 +- .bash_profile | 15 +- .bash_prompt | 38 +++- .bash_prompt_ubuntu | 31 --- .bashrc | 131 ++++-------- .debug | 6 - .env | 31 --- .functions | 56 ----- .gitconfig | 14 -- .gitignore | 1 + .gitignore_global | 2 - .go_arm64 | 6 - .../.hammerspoon => .hammerspoon}/init.lua | 0 .perf | 7 - .prompt | 0 .serv | 38 ---- .ubuntu | 17 -- .vimrc | 2 +- .zsh_prompt | 0 .zshrc | 48 ----- Brewfile | 15 -- Makefile | 13 -- banner.sh | 9 - bootstrap.sh | 63 +++++- greetings.sh | 2 - hammerspoon/bootstrap_hammerspoon.sh | 3 - 34 files changed, 603 insertions(+), 556 deletions(-) delete mode 100644 .alias_docker delete mode 100644 .alias_git delete mode 100644 .alias_middleware delete mode 100644 .aliases create mode 100644 .bash_alias create mode 100644 .bash_bin create mode 100644 .bash_darwin rename .alias_k8s => .bash_k8s (79%) rename .centos7 => .bash_linuxgnu (75%) delete mode 100644 .bash_prompt_ubuntu delete mode 100644 .debug delete mode 100644 .env delete mode 100644 .functions delete mode 100644 .gitconfig create mode 100644 .gitignore delete mode 100644 .gitignore_global delete mode 100644 .go_arm64 rename {hammerspoon/.hammerspoon => .hammerspoon}/init.lua (100%) delete mode 100644 .perf delete mode 100644 .prompt delete mode 100644 .serv delete mode 100644 .ubuntu delete mode 100644 .zsh_prompt delete mode 100644 .zshrc delete mode 100644 Brewfile delete mode 100644 Makefile delete mode 100644 banner.sh delete mode 100644 greetings.sh delete mode 100644 hammerspoon/bootstrap_hammerspoon.sh diff --git a/.alias_docker b/.alias_docker deleted file mode 100644 index edb64c7..0000000 --- a/.alias_docker +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -alias dps="docker ps -a" -alias di="docker images" -alias dbuild='docker build -t' -alias drm="docker rm -f" -alias drmi="docker rmi" -alias dstop="docker stop" -alias dc="docker-compose" - -alias dms5="docker run --name imysql5.7 -e MYSQL_ROOT_PASSWORD=root --platform linux/x86_64 -p 3306:3306 -d mysql:5.7" -alias dms8="docker run --name imysql8 -e MYSQL_ROOT_PASSWORD=root --platform linux/x86_64 -p 3306:3306 -d mysql:8" -alias drds="docker run -d --name iredis -p 6379:6379 redis" -alias drds2="f(){ docker run -d --name $1 -p 6379:6379 redis; unset -f f; }; f" diff --git a/.alias_git b/.alias_git deleted file mode 100644 index 4b55dba..0000000 --- a/.alias_git +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -alias gs='git status' -alias gcm="git commit -m" -alias gl="git log --oneline --decorate --color" -alias glh="git log --all --graph --decorate --oneline" -alias gst="git stash -u" -alias gust="git restore --staged ." -alias gb="git branch" -alias gc="git checkout" -alias gdiff="git diff" -alias grh="git reset --hard HEAD" diff --git a/.alias_middleware b/.alias_middleware deleted file mode 100644 index 90e204d..0000000 --- a/.alias_middleware +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash - -# TODO: chose by arch -alias jdk8="export JAVA_HOME=/Users/luca/Library/Java/JavaVirtualMachines/adopt-openjdk-1.8.0_292/Contents/Home" -alias jdk11="export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home" - -JENKINS_VERSION=2.319.3 -JENKINS_LOCATION="${HOME}/bin/jenkins-${JENKINS_VERSION}-LTS.war" - -function jenkins() { - case $1 in - start) - if [ ! -f "${JENKINS_LOCATION}" ]; then - echo "${JENKINS_LOCATION} not be found locally, download through wget...}" - #wget -P "${JENKINS_LOCATION}" https://get.jenkins.io/war-stable/${JENKINS_VERSION}/jenkins.war - fi - - echo "jenkins jdk uses version 8 by default" - # TODO: enable jdk8 - - local HTTP_PORT=$2 - [ -z "${HTTP_PORT}" ] && HTTP_PORT=8080 && echo "jenkins http port listen at 8080 by default " - - echo "java -jar ${HTTP_PORT}" - #java -jar jenkins-${JENKINS_VERSION}-LTS.war --httpPort="${HTTP_PORT}" - ;; - - *) - printf "jenkins unknown args: %s\n" "$*" - ;; - esac -} - -# 查找本机的内网IP -alias inetip="ifconfig | grep 'inet'" - -alias nacos-namingserv-standalone='jdk8 && sh /Users/luca/bin/nacos-register-standalone/bin/startup.sh -m standalone && tail -f /Users/luca/bin/nacos-register-standalone/logs/start.out' -alias nacos-namingserv-cluster='' - -alias nacos-configserv-standalone='' -alias nacos-configserv-cluster='' - -alias kafka-standalone='' - -alias rabbitmq-standalone='' - -alias elasticsearch-standalone='' - -# TODO: find java diff --git a/.aliases b/.aliases deleted file mode 100644 index c035ab4..0000000 --- a/.aliases +++ /dev/null @@ -1,69 +0,0 @@ -alias mkdir='mkdir -v' -alias mv='mv -v' -alias cp='cp -v' -alias rm='rm -v' -alias rmnm='rm -rf node_modules > /dev/null' -alias ln='ln -v' - -# HELP -alias cs="f(){ curl "cheat.sh/$1"; unset -f f; }; f" - -# NAVIGATION -alias ..="cd .." -alias ...="cd ../.." -alias ....="cd ../../.." -alias .....="cd ../../../.." - -# Shortcut -alias reload="source ~/.bash_profile" -alias _="sudo" -alias rr="rm -rf" -alias hosts="sudo $EDITOR /etc/hosts" -alias quit="exit" -alias l="ls -la" -alias ~="cd ~" -alias cdev="cd ~/dev" -alias cbin="cd ~/bin" -alias path="echo -e ${PATH//:/\\n}" - -# Always enable colored `grep` output -alias grep='grep --color=auto' -alias fgrep='fgrep --color=auto' -alias egrep='egrep --color=auto' - -# npm -alias nreload="rm -rf node_modules/ package-lock.json && npm install" -alias ni="npm install" -alias cni="cnpm install" -alias ns="kill -9 $(lsof -ti:3000,3001) && npm start" - -# Network -alias pingg="ping www.google.com" -alias pingb="ping www.baidu.com" - -# HTTP Proxy -alias enable-vpn="export http_proxy='http://localhost:8010' && curl cip.cc" -alias disable-vpn="unset http_proxy && curl cip.cc" -alias vpn-status="curl cip.cc" -alias whereami='curl cip.cc' -alias pubip='curl ifconfig.cc; echo' - -# 开启 GoLang 1.17.x 泛型特性 -alias grg="go run -gcflags=-G=3" - -# Intuitive map function -# For example, to list all directories that contain a certain file: -# find . -name .gitattributes | map dirname -alias map="xargs -n1" - -# nginx -alias ng='nginx' # ng -t - -# redis -alias rds-install='brew update; brew install redis' -alias rds-server='redis-server /usr/local/etc/redis.conf' -alias rds-cli='redis-cli' -alias rds-ping='redis-cli ping' - -alias pip='pip3' -alias python='python3' diff --git a/.bash_alias b/.bash_alias new file mode 100644 index 0000000..cefbd08 --- /dev/null +++ b/.bash_alias @@ -0,0 +1,199 @@ +#!/bin/bash + +# HELP +function cs() { + curl "cheat.sh/$1" +} +export -f cs + + +############# +# Git +############# +alias gs="git status" +alias gcm="git commit -m" +alias gl="git log --oneline --decorate --color" +alias glh="git log --all --graph --decorate --oneline" +alias gst="git stash -u" +alias gust="git restore --staged ." +alias gb="git branch" +alias gc="git checkout" +alias gdiff="git diff" +alias grh="git reset --hard HEAD" +alias gaa='git add .' +alias gaaa='git add -A' +alias gi='git init' +alias gp='git pull' +alias gpsh='git push' +alias gss='git status -s' + + +############# +# Node +############# +# TODO nvm +# TODO nrm npm registry manager +alias rmnm="rm -r ./node_modules/" +alias ns='npm start' +alias start='npm start' +alias nr='npm run' +alias run='npm run' +alias ni="npm install" +alias cni="cnpm install" +alias nis='npm i -S' +alias nreload="rm -rf node_modules/ package-lock.json && npm install" +alias ns="kill -9 $(lsof -ti:3000,3001) && npm start" + + +############# +# Pip +############# +alias pip="pip3" +alias python="python3" + + +############# +# Common +############# +alias mkdir='mkdir -v' +alias mv='mv -v' +alias cp='cp -v' +alias rm='rm -v' # rm -i +alias rmnm='rm -rf node_modules > /dev/null' +alias ln='ln -v' + +# NAVIGATION +alias ..="cd .." +alias ...="cd ../.." +alias ....="cd ../../.." +alias .....="cd ../../../.." + +# SHORTCUT +alias reload="source ~/.bash_profile" +alias _="sudo" +alias rr="rm -rf" +alias hosts="sudo $EDITOR /etc/hosts" +alias quit="exit" +alias l="ls -la" +alias ~="cd ~" +alias cdev="cd ~/dev" +alias cbin="cd ~/bin" +alias path="echo -e ${PATH//:/\\n}" + +alias e?='echo $?' +alias vi='vim' + +# Always enable colored `grep` output +alias grep='grep --color=auto' +alias fgrep='fgrep --color=auto' +alias egrep='egrep --color=auto' + +alias a='code .' +alias reveal-md="reveal-md --theme night --highlight-theme hybrid --port 1337" +alias o="open ." # Open the current directory in Finder + +function ccat() { + local style="monokai" + if [ $# -eq 0 ]; then + pygmentize -P style=$style -P tabsize=4 -f terminal256 -g + else + # shellcheck disable=SC2068 + for NAME in $@; do + pygmentize -P style=$style -P tabsize=4 -f terminal256 -g "$NAME" + done + fi +} + +function extract () { + if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar xvjf $1 ;; + *.tar.gz) tar xvzf $1 ;; + *.bz2) bunzip2 $1 ;; + *.rar) unrar x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xvf $1 ;; + *.tbz2) tar xvjf $1 ;; + *.tgz) tar xvzf $1 ;; + *.zip) unzip $1 ;; + *.Z) uncompress $1 ;; + *.7z) 7z x $1 ;; + *) echo "don't know how to extract '$1'..." ;; + esac + else + echo "'$1' is not a valid file!" + fi +} + +# Create a new directory and enter it +function mkd() { + mkdir -p "$@" && cd "$_"; +} + +function mkcd() { + mkdir $1 && cd $1 +} + +# `o` with no arguments opens the current directory, +# otherwise opens the given location. +function o() { + if [ $# -eq 0 ]; then + open .; + else + open "$@"; + fi; +} + +# Intuitive map function +# For example, to list all directories that contain a certain file: +# find . -name .gitattributes | map dirname +alias map="xargs -n1" + +# Process +alias pbyport='netstat -vanp tcp | grep' +alias killbyport='' +alias rmjobs='kill -9 $(jobs -p)' + + +############# +# Hexo +############# +alias hs="hexo clean && hexo g && hexo s" + + +################## +# HTTP Proxy +################## +alias vpn-enable="export http_proxy='http://localhost:8010' && curl cip.cc" +alias vpn-disable="unset http_proxy && curl cip.cc" +alias vpn-status="curl cip.cc" +alias whereami='curl cip.cc' +alias pubip='curl ifconfig.cc; echo' +alias pingg="ping www.google.com" +alias pingb="ping www.baidu.com" + + +#################################################################### +# Color +#################################################################### +bldgrn='\e[1;32m' # Bold Green +bldpur='\e[1;35m' # Bold Purple +txtrst='\e[0m' # Text Reset + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' # No Color + +function red { + printf "${RED}$@${NC}\n" +} + +function green { + printf "${GREEN}$@${NC}\n" +} + +function yellow { + printf "${YELLOW}$@${NC}\n" +} + diff --git a/.bash_bin b/.bash_bin new file mode 100644 index 0000000..c8b6566 --- /dev/null +++ b/.bash_bin @@ -0,0 +1,199 @@ +#!/bin/bash + +############## +# MySQL +############## +alias dmysql5="docker run --name imysql5.7 -e MYSQL_ROOT_PASSWORD=root --platform linux/x86_64 -p 3306:3306 -d mysql:5.7" +alias dmysql8="docker run --name imysql8 -e MYSQL_ROOT_PASSWORD=root --platform linux/x86_64 -p 3306:3306 -d mysql:8" +alias bmysql="brew services start mysql" # pwd:12345678 https://stackoverflow.com/a/62461889 +alias bmysqlstop="brew services stop mysql" +alias bmysqlrestart="brew services restart mysql" +alias binmysql="" + + +############## +# Redis +############## +alias dredis="docker run -d --name iredis -p 6379:6379 redis" +function dredis2() { + docker run -d --name $1 -p 6379:6379 redis; +} +export -f dredis2 +alias brew-redis="" +alias brew-redis-stop="" +alias bin-redis="" +#alias rds-install='brew update; brew install redis' +#alias rds-server='redis-server /usr/local/etc/redis.conf' +alias rdcli="redis-cli" +alias rdclip="redis-cli ping" + + +############## +# Nginx +############## +alias ng="nginx" +alias ngt="nginx -t" + + +############## +# RabbitMQ +############## +alias damqp="docker run --rm -d --hostname my-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management" +alias amqp-dashboard='firefox http://127.0.0.1:15672' + + +############## +# Kafka +############## +alias dkakfa="" + +function kafka-start() { + local PREV_ZK_PID=$(lsof -t -i :2181 -s TCP:LISTEN) + if [ -n "${PREV_ZK_PID}" ]; then + echo -e "\n==> Zookeeper server already in port 2181, pid: ${PREV_ZK_PID}" + else + echo -e "\n==> Start the ZooKeeper service..." + ~/bin/kafka_2.13-3.1.0/bin/zookeeper-server-start.sh ~/bin/kafka_2.13-3.1.0/config/zookeeper.properties > /dev/null 2>&1 & + sleep 1 + local ZK_PID=$(echo "$!") + echo "==> ZooKeeper server Started! PID: ${ZK_PID}" + fi + + local PREV_KAFKA_BROKER_PID=$(lsof -t -i :9092 -s TCP:LISTEN) + if [ -n "${PREV_KAFKA_BROKER_PID}" ]; then + echo -e "\n==> kafka broker already in port 9092, pid: ${PREV_KAFKA_BROKER_PID}" + else + echo -e "\n==> Start the Kafka broker service..." + ~/bin/kafka_2.13-3.1.0/bin/kafka-server-start.sh ~/bin/kafka_2.13-3.1.0/config/server.properties > /dev/null 2>&1 & + sleep 1 + local KAFKA_BROKER_PID=$(echo "$!") + echo "==> Kafka broker Started! PID: ${KAFKA_BROKER_PID}" + fi +} +export -f kafka-start + +function kafka-stop() { + local ZK_PID=$(lsof -t -i :2181 -s TCP:LISTEN) + if [ -z "${ZK_PID}" ]; then + echo -e "\n==> Zookeeper server not found in port 2181" + else + kill -9 "${ZK_PID}" && sleep 1 + echo -e "\n==> Zookeeper server stoped" + fi + + local KAFKA_BRKOER_PID=$(lsof -t -i :9092 -s TCP:LISTEN) + if [ -z "${KAFKA_BRKOER_PID}" ]; then + echo -e "\n==> Kafka broker not found in port 9092" + else + kill -9 "${KAFKA_BRKOER_PID}" && sleep 1 + echo -e "\n==> Kafka broker stoped" + fi + + echo -e "\n==> Release zookeeper server and kafka broker's cached files" + rm -rf /tmp/kafka-logs /tmp/zookeeper > /dev/null + echo -e "\n==> done!" +} +export -f kafka-stop + +function kafka-create-topic() { + local TOPIC_NAME= + if [ -n "$1" ]; then + TOPIC_NAME=$1 + else + echo -e "\n==> TOPIC NAME not supplied, use 'quickstart-events' by default.\n" + TOPIC_NAME=quickstart-events + fi + ~/bin/kafka_2.13-3.1.0/bin/kafka-topics.sh --create --topic "${TOPIC_NAME}" --bootstrap-server localhost:9092 + echo -e "\n==>TOPIC DESCRIPTION will be printed, Wait 1 seconds...\n" && sleep 1 + ~/bin/kafka_2.13-3.1.0/bin/kafka-topics.sh --describe --topic "${TOPIC_NAME}" --bootstrap-server localhost:9092 | xargs -n 2 +} +export -f kafka-create-topic + +function kafka-reader() { + if [ -z "$1" ]; then + echo -e "TOPIC NAME not supplied" && exit 1 + fi + ~/bin/kafka_2.13-3.1.0/bin/kafka-console-consumer.sh --topic "$1" --from-beginning --bootstrap-server localhost:9092 +} +export -f kafka-reader + +function kafka-writer() { + if [ -z "$1" ]; then + echo -e "TOPIC NAME not supplied" && exit 1 + fi + ~/bin/kafka_2.13-3.1.0/bin/kafka-console-producer.sh --topic "$1" --bootstrap-server localhost:9092 +} +export -f kafka-writer + + +############## +# Elasticsearch +############## +alias des="" +alias dlogstash='sudo ~/bin/logstash-7.1.0/bin/logstash -f logstash.conf' + + +############## +# Mongo +############## +#PATH=$PATH:/Users/luca/mongodb/mongodb-macos-x86_64-5.0.5/bin +#alias mongo-up='mongod --dbpath /usr/local/var/mongodb' + + +############## +# HBase +############## +# TODO export HBASE_HOME="" +alias hbase-start-slient='hbase' +alias hbase-dashboard='firefox 127.0.0.1:16010' + + +############## +# Easegress +############## +alias easegress-server-start='~/bin/easegress/bin/easegress-server' +alias easegress-server-reload='cd ~/bin/easegress && make && easegress-start' +alias egctl-reload='cd ~/bin/easegress && make' +alias egctl='~/bin/easegress/bin/egctl' +alias easegress-mock-srvs='go run ~/bin/easegress/example/backend-service/mirror/mirror.go &' + + +############## +# Nacos +############## +alias nacos-namingserv-standalone='sh ~/bin/nacos-register-standalone/bin/startup.sh -m standalone && tail -f ~/bin/nacos-register-standalone/logs/start.out' +alias nacos-namingserv-cluster='' + +alias nacos-configserv-standalone='' +alias nacos-configserv-cluster='' + + +############## +# Jenkins +############## +JENKINS_VERSION=2.319.3 +JENKINS_LOCATION="${HOME}/bin/jenkins-${JENKINS_VERSION}-LTS.war" + +function jenkins() { + case $1 in + start) + if [ ! -f "${JENKINS_LOCATION}" ]; then + echo "${JENKINS_LOCATION} not be found locally, download through wget...}" + #wget -P "${JENKINS_LOCATION}" https://get.jenkins.io/war-stable/${JENKINS_VERSION}/jenkins.war + fi + + echo "jenkins jdk uses version 8 by default" + # TODO: enable jdk8 + + local HTTP_PORT=$2 + [ -z "${HTTP_PORT}" ] && HTTP_PORT=8080 && echo "jenkins http port listen at 8080 by default " + + echo "java -jar ${HTTP_PORT}" + #java -jar jenkins-${JENKINS_VERSION}-LTS.war --httpPort="${HTTP_PORT}" + ;; + + *) + printf "jenkins unknown args: %s\n" "$*" + ;; + esac +} diff --git a/.bash_darwin b/.bash_darwin new file mode 100644 index 0000000..a85ff00 --- /dev/null +++ b/.bash_darwin @@ -0,0 +1,28 @@ +#!/bin/bash + +# functions +function chrome() { + open -a "Google Chrome" $1 +} +export -f chrome + +function firefox() { + open -a "firefox" $1 +} +export -f firefox + +# Java Env + +# Python Env + +# Go Env +#export GOROOT= +export GOPATH=~/go +#export PATH=$GOPATH/bin:$PATH + +export GO111MODULE="on" +export GOPROXY=https://goproxy.cn,direct +export GOPRIVATE= +export GOSUMDB=off + +alias grg="go run -gcflags=-G=3" # 开启 GoLang 1.17.x 泛型特性 diff --git a/.alias_k8s b/.bash_k8s similarity index 79% rename from .alias_k8s rename to .bash_k8s index 7597fba..ac83bfc 100644 --- a/.alias_k8s +++ b/.bash_k8s @@ -1,11 +1,33 @@ #!/bin/bash +################## +# Docker +################## +alias dps="docker ps -a" +alias di="docker images" +alias dbuild='docker build -t' +alias drm="docker rm -f" +alias drmi="docker rmi" +alias dstop="docker stop" +alias dc="docker-compose" + +# alpine镜像默认的软件仓库在国外, 有时 `docker build` 的时候安装软件包会很慢, 可以改用国内的软件包镜像 +alias alpine-ustc='RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.ustc.edu.cn/!g' /etc/apk/repositories' + + +################## +# Minikube +################## alias mk='minikube' alias mks='minikube start --driver=docker --force' alias mks2='minikube start --driver=docker --force --node=2' alias mkssh='minikube ssh' + +################## +# Kubectl # https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands +################## alias k='kubectl' # k --help alias kar='kubectl api-resources' alias ke='kubectl explain' # ke po.metadata @@ -19,9 +41,6 @@ alias klf='kubectl logs -f --tail=100' alias kccm='kubectl create cm' # kccm app-config --from-literal=HTTP_PROXY=http://localhost:8010 alias kpf='kubectl port-forward' # kpf fortune 8080:80 -# alpine镜像默认的软件仓库在国外, 有时 `docker build` 的时候安装软件包会很慢, 可以改用国内的软件包镜像 -alias alpine-ustc='RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.ustc.edu.cn/!g' /etc/apk/repositories' - # Explore k8s API alias kube1="kubectl get --raw / | jq ." alias kube2="kubectl get --raw /api | jq ." diff --git a/.centos7 b/.bash_linuxgnu similarity index 75% rename from .centos7 rename to .bash_linuxgnu index 10722b2..ea7def4 100644 --- a/.centos7 +++ b/.bash_linuxgnu @@ -1,30 +1,36 @@ #!/bin/bash +# 查找本机的内网IP +alias inetip="ifconfig | grep 'inet'" alias cdnet='cd /etc/sysconfig/network-scripts/' +alias upt='uptime' +# 查看系统有几个CPU +alias cpus="grep 'model name' /proc/cpuinfo | wc -l" + # firewall daemon function firewalld() { case $1 in status) systemctl status firewalld.service ;; - + start) systemctl start firewalld.service ;; - + stop) systemctl stop firewalld.service ;; - + disable) systemctl disable firewalld.service ;; - + enable) systemctl enable firewalld.service ;; - + *) #printf "unknown args: %s\n" "$@" printf "unknown args: %s\n" "$*" diff --git a/.bash_profile b/.bash_profile index 18e679e..9575261 100644 --- a/.bash_profile +++ b/.bash_profile @@ -1,8 +1,17 @@ -echo "Greetings Luca! I'm .bash_profile" +echo && cal + +if [ -f ~/.bashrc ]; then + . ~/.bashrc +fi + + +# Setting PATH for Python 3.10 +# The original version is saved in .bash_profile.pysave +export PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}" + # HomeBrew export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles export PATH="/usr/local/bin:$PATH" export PATH="/usr/local/sbin:$PATH" -# HomeBrew END - +# HomeBrew END \ No newline at end of file diff --git a/.bash_prompt b/.bash_prompt index 577d3c7..3548ee7 100644 --- a/.bash_prompt +++ b/.bash_prompt @@ -1,15 +1,37 @@ -# https://stackoverflow.com/questions/35281630/how-do-i-change-my-ps1-on-a-macbook-for-oh-my-zsh +#!bin/bash + +HOST_NAME=Luca + +# TODO https://unix.stackexchange.com/questions/2897/clicolor-and-ls-colors-in-bash +export CLICOLOR=1 +export LSCOLORS=GxFxCxDxBxegedabagaced + +txtred='\e[0;31m' # Red +txtgrn='\e[0;32m' # Green +bldgrn='\e[1;32m' # Bold Green +bldpur='\e[1;35m' # Bold Purple +txtrst='\e[0m' # Text Reset + parse_git_branch() { - pr=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/') - if [ -z ${pr} ]; then - echo "" + pr=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/') + if [ -z ${pr} ]; then + echo "" return; - fi + fi + echo " git:${pr}" +} - echo " git:${pr}" +print_before_the_prompt () { + dir=$PWD + home=$HOME + dir=${dir/"$HOME"/"~"} + printf "\n $txtred%s: $bldpur%s $txtgrn%s\n$txtrst" "$HOST_NAME" "$dir" "$(vcprompt)" } -emojis=("🚀" "🍻" "👙" "🍺") +emojis=("🚀" "😈" "🍻" "👙" "🍺") EMOJI=${emojis[$RANDOM % ${#emojis[@]} ]} -export PS1="🧸 \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] ${EMOJI} $ " \ No newline at end of file +PROMPT_COMMAND=print_before_the_prompt +PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" +PS1="$EMOJI => " + diff --git a/.bash_prompt_ubuntu b/.bash_prompt_ubuntu deleted file mode 100644 index f051d22..0000000 --- a/.bash_prompt_ubuntu +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# GIT FUNCTIONS -git_branch() { - git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' -} - -git_dirty() { - local GLAG - if [[ -n `git status --porcelain --untracked-files=no 2> /dev/null` ]]; then - FLAG=('‼️ ') - else - FLAG=('👍') - fi - if [[ -n `git branch 2> /dev/null` ]]; then - echo "$FLAG" - fi -} - -# TERMINAL PROMPT -PS1="\[\e[0;93m\]KATE \[\e[m\]" # username -PS1+=" " # space -PS1+="\[\e[0;95m\]\W\[\e[m\]" # current directory -PS1+="\[\e[0;92m\]\$(git_branch) \[\e[m\]" # current branch -PS1+="\[\e[0;92m\]\$(git_dirty)\[\e[m\]" # work tree clean/dirty -PS1+="\n" # new line -PS1+="$ " # end prompt -export PS1; - -export CLICOLOR=1 -export LSCOLORS=exfxbxdxcxegedabagacad diff --git a/.bashrc b/.bashrc index d606b4b..13f67dc 100644 --- a/.bashrc +++ b/.bashrc @@ -1,100 +1,51 @@ -#################################################################### -# Greetings -#################################################################### -cat ~/banner.txt -python3 ~/idioms.py -echo -e "\n" - - -#################################################################### -# Basic configuration -#################################################################### -export PATH=$PATH:~/bin - # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi -PATH="$HOME/.local/bin:$HOME/bin:$PATH" -export PATH -export LANG="en_US.UTF-8" -export DEV="~/dev" - -# Configure for git -export PATH=/usr/local/libexec/git-core:$PATH - - -#################################################################### -# Color -#################################################################### -bldgrn='\e[1;32m' # Bold Green -bldpur='\e[1;35m' # Bold Purple -txtrst='\e[0m' # Text Reset - -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -NC='\033[0m' # No Color - -function red { - printf "${RED}$@${NC}\n" -} - -function green { - printf "${GREEN}$@${NC}\n" -} - -function yellow { - printf "${YELLOW}$@${NC}\n" -} - - -#################################################################### -# Aliases -#################################################################### -alias rm='rm -i' -alias cp='cp -i' -alias mv='mv -i' -alias vi='nvim' -alias l='ls' -alias ll='ls -al' -alias e?='echo $?' -alias vi='vim' -alias ll='ls -alh --color=auto | sort' - -#################################################################### -# Functions -#################################################################### -function ccat() { - local style="monokai" - if [ $# -eq 0 ]; then - pygmentize -P style=$style -P tabsize=4 -f terminal256 -g - else - for NAME in $@; do - pygmentize -P style=$style -P tabsize=4 -f terminal256 -g "$NAME" - done - fi -} - - -#################################################################### -# Go envs -#################################################################### -export GOVERSION=go1.16.2 -export GO_INSTALL_DIR=$HOME/go -export GOROOT=$GO_INSTALL_DIR/$GOVERSION -export GOPATH=$DEV/golang -export PATH=$GOROOT/bin:$GOPATH/bin:$PATH -export GO111MODULE="on" + +#fortune | cowsay -f tux + + +export LC_ALL=en_US.UTF-8 +export LANG=en_US.UTF-8 + +export PATH=$PATH:$HOME/bin +export HISTSIZE=5000 +export HISTFILESIZE=10000 +#export EDITOR="code -w" +export EDITOR='vim' + + +source ~/.nvm/nvm.sh +nvm use stable + + +shopt -s autocd +shopt -s histappend + + +bind '"\e[A": history-search-backward' +bind '"\e[B": history-search-forward' + + +export GOPATH=$HOME/go export GOPROXY=https://goproxy.cn,direct -export GOPRIVATE= +export GOPRIVATE=*.cds8.cn +export GO111MODULE="on" export GOSUMDB=off +#export GOOS=darwin +#export GOARCH=arm64 +export PATH=$GOPATH/bin:$PATH -#################################################################### -# Initial -#################################################################### -#cd $DEV - +source ~/.bash_alias +source ~/.bash_bin +source ~/.bash_k8s +source ~/.bash_darwin source ~/.bash_prompt + + +eval "$(/opt/homebrew/bin/brew shellenv)" +export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git" +#brew update diff --git a/.debug b/.debug deleted file mode 100644 index 3223da1..0000000 --- a/.debug +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# easegress -export PATH=${PATH}:/Users/luca/dev-opensource/easegress/bin/ - -# TODO: strace, gdb, cc, gcc diff --git a/.env b/.env deleted file mode 100644 index de268d4..0000000 --- a/.env +++ /dev/null @@ -1,31 +0,0 @@ -export PATH=$HOME/bin:/usr/local/bin:$PATH - -# Set macOS default editor to VSCode -#export EDITOR="code -w" - -# Make vim the default editor -export EDITOR='vim' - -export ZSH="/Users/luca/.oh-my-zsh" - -# Compilation flags -export ARCHFLAGS="-arch x86_64" - -export LANG=en_US.UTF-8 - -export MANPATH="/usr/local/man:$MANPATH" - -# nvm -export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" - -export DEV=/Users/luca/dev - -# Go -export GOROOT=/usr/local/go -export GOPATH=$DEV/golang -export PATH=$GOROOT/bin:$GOPATH/bin:$PATH -export GO111MODULE=on -export GOPROXY=https://goproxy.cn,direct -export GOPRIVATE= -export GOSUMDB=off diff --git a/.functions b/.functions deleted file mode 100644 index 5fba68e..0000000 --- a/.functions +++ /dev/null @@ -1,56 +0,0 @@ -function ccat() { - local style="monokai" - if [ $# -eq 0 ]; then - pygmentize -P style=$style -P tabsize=4 -f terminal256 -g - else - # shellcheck disable=SC2068 - for NAME in $@; do - pygmentize -P style=$style -P tabsize=4 -f terminal256 -g "$NAME" - done - fi -} - -function extract () { - if [ -f $1 ] ; then - case $1 in - *.tar.bz2) tar xvjf $1 ;; - *.tar.gz) tar xvzf $1 ;; - *.bz2) bunzip2 $1 ;; - *.rar) unrar x $1 ;; - *.gz) gunzip $1 ;; - *.tar) tar xvf $1 ;; - *.tbz2) tar xvjf $1 ;; - *.tgz) tar xvzf $1 ;; - *.zip) unzip $1 ;; - *.Z) uncompress $1 ;; - *.7z) 7z x $1 ;; - *) echo "don't know how to extract '$1'..." ;; - esac - else - echo "'$1' is not a valid file!" - fi -} - -# Create a new directory and enter it -function mkd() { - mkdir -p "$@" && cd "$_"; -} - -# `o` with no arguments opens the current directory, -# otherwise opens the given location. -function o() { - if [ $# -eq 0 ]; then - open .; - else - open "$@"; - fi; -} - -# Start a redis Container -function drd() { - if [ $# -eq 0 ]; then - docker run -di --name iredis -p 6379:6379 redis; - else - docker run -di --name "$1" -p "$2":6379 redis; - fi; -} diff --git a/.gitconfig b/.gitconfig deleted file mode 100644 index 9201c6f..0000000 --- a/.gitconfig +++ /dev/null @@ -1,14 +0,0 @@ -[user] - name = Luca - email = yangshaoxiong5545@gmail.com -[core] - excludesfile = /Users/luca/.gitignore_global - autocrlf = input -[difftool "sourcetree"] - cmd = opendiff \"$LOCAL\" \"$REMOTE\" - path = -[mergetool "sourcetree"] - cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\" - trustExitCode = true -[commit] - template = /Users/luca/.stCommitMsg diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/.gitignore_global b/.gitignore_global deleted file mode 100644 index 93bfd12..0000000 --- a/.gitignore_global +++ /dev/null @@ -1,2 +0,0 @@ -*~ -.DS_Store diff --git a/.go_arm64 b/.go_arm64 deleted file mode 100644 index 7d745a7..0000000 --- a/.go_arm64 +++ /dev/null @@ -1,6 +0,0 @@ -export GOPATH=$HOME/go -export GOPROXY=https://goproxy.cn,direct -export GOPRIVATE= -export GO111MODULE="on" -export GOSUMDB=off -export PATH=$GOPATH/bin:$PATH \ No newline at end of file diff --git a/hammerspoon/.hammerspoon/init.lua b/.hammerspoon/init.lua similarity index 100% rename from hammerspoon/.hammerspoon/init.lua rename to .hammerspoon/init.lua diff --git a/.perf b/.perf deleted file mode 100644 index 1de1c22..0000000 --- a/.perf +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -alias upt='uptime' -# 查看系统有几个CPU -alias cpus="grep 'model name' /proc/cpuinfo | wc -l" - -# TODO: nc diff --git a/.prompt b/.prompt deleted file mode 100644 index e69de29..0000000 diff --git a/.serv b/.serv deleted file mode 100644 index 4b6e400..0000000 --- a/.serv +++ /dev/null @@ -1,38 +0,0 @@ -function chrome() { - open -a "Google Chrome" $1 -} -export -f chrome - -function firefox() { - open -a "firefox" $1 -} -export -f firefox - -export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home" -export HBASE_HOME="" - -# hbase -hbase-start-slient='hbase' -hbase-dashboard='firefox 127.0.0.1:16010' - -# RabbitMQ -# https://codeburst.io/get-started-with-rabbitmq-on-docker-4428d7f6e46b -rabbitmq-dashboard='firefox http://127.0.0.1:15672' - -# Kibana -kibana-dashboard='firefox http://127.0.0.1:5601' - - -# MySQL -alias startmsql='brew services start mysql' -# https://stackoverflow.com/a/62461889 -# mysql -uroot -p12345678 -alias stopmysql='brew services stop mysql' -alias restartmysql='brew services restart mysql' - - -alias damqp="docker run --rm -d --hostname my-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management" -alias dkakfa="" -alias des="" - -alias dlogstash='sudo ~/bin/logstash-7.1.0/bin/logstash -f logstash.conf' \ No newline at end of file diff --git a/.ubuntu b/.ubuntu deleted file mode 100644 index 6ecf923..0000000 --- a/.ubuntu +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# 从阿里云的容器服务中获取专属ID -REGISTRY_MIRROR_ID= - -function aliyun-docker-mirror() { - sudo mkdir -p /etc/docker - sudo tee /etc/docker/daemon.json <<-EOF -{ - "registry-mirrors": ["https://${REGISTRY_MIRROR_ID}.mirror.aliyuncs.com"] -} -EOF - sudo systemctl daemon-reload - sudo systemctl restart docker -} - -#现代编程中,应该摒弃继承,转而使用组合,手段再丰富点,辅以 Trait、Mixin 等方式。 diff --git a/.vimrc b/.vimrc index 4d7a7f0..1ea00c1 100644 --- a/.vimrc +++ b/.vimrc @@ -7,4 +7,4 @@ set hlsearch "tab字符占据的列数, 默认是8列 set tabstop=4 "新行缩进与上一行相同的列数 -set autoindent +set autoindent \ No newline at end of file diff --git a/.zsh_prompt b/.zsh_prompt deleted file mode 100644 index e69de29..0000000 diff --git a/.zshrc b/.zshrc deleted file mode 100644 index 88f7744..0000000 --- a/.zshrc +++ /dev/null @@ -1,48 +0,0 @@ -PATH=$PATH:/Users/luca/mongodb/mongodb-macos-x86_64-5.0.5/bin -alias mongo-up='mongod --dbpath /usr/local/var/mongodb' - -# Greetings -#source ~/banner.sh -echo -cal -python3 $HOME/idioms.py - -# Recommendation -echo -echo '👇 Try this: ' -echo '- (TODO:做成函数) curl cheat.sh/cal' -echo '- cmatrix' -echo '- https://explainshell.com/explain?cmd=pstree+-p' -echo '- find xarg trash' - -# Load configuration -source ~/.env -source ~/.aliases -source ~/.alias_git -source ~/.alias_docker -source ~/.alias_k8s -source ~/.functions - -# Enable smart completion -autoload -U compinit -compinit - -# Automatically update without prompting. -DISABLE_UPDATE_PROMPT="true" - -# ZSH THEMES -#ZSH_THEME="agnoster" -#ZSH_THEME="awesomepanda" -#ZSH_THEME="Avit" - -# Zsh Plugins -plugins=( - git - history - jsontools - - zsh-syntax-highlighting - zsh-autosuggestions -) - -source $ZSH/oh-my-zsh.sh diff --git a/Brewfile b/Brewfile deleted file mode 100644 index f77ee34..0000000 --- a/Brewfile +++ /dev/null @@ -1,15 +0,0 @@ -tap "homebrew/bundle" -tap "homebrew/cask", "https://mirrors.ustc.edu.cn/homebrew-cask.git" -tap "homebrew/core", "https://mirrors.ustc.edu.cn/homebrew-core.git" -# Internet file retriever -brew "wget" -# Application launcher and productivity software -cask "alfred" -# Proxy/VPN client -cask "brook" -# Web browser -cask "firefox" -# Terminal emulator as alternative to Apple's Terminal app -cask "iterm2" -# Move and resize windows using keyboard shortcuts or snap areas -cask "rectangle" diff --git a/Makefile b/Makefile deleted file mode 100644 index c9e7456..0000000 --- a/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -.PHONY: ln -ln: - ## MacOS - ln -s ~/.dotfiles/.zshrc ~/.zshrc - ln -s ~/.dotfiles/banner.sh ~/banner.sh - ln -s ~/.dotfiles/.env ~/.env - ln -s ~/.dotfiles/.aliases ~/.aliases - ln -s ~/.dotfiles/.functions ~/.functions - ln -s ~/.dotfiles/idioms.py ~/idioms.py - - ln -s ~/.dotfiles/.gitconfig ~/.gitconfig - ln -s ~/.dotfiles/.gitignore_global ~/.gitignore_global - ln -s ~/.dotfiles/.vimrc ~/.vimrc diff --git a/banner.sh b/banner.sh deleted file mode 100644 index 4afb4ed..0000000 --- a/banner.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -echo "" -echo " __ __ __ __ _ __ __ __ __ - / / / /___ / // /____ | | / /____ _____ / /____/ // / - / /_/ // _ \ / // // __ \ | | /| / // __ \ / ___// // __ // / - / __ // __// // // /_/ / | |/ |/ // /_/ // / / // /_/ //_/ -/_/ /_/ \___//_//_/ \____/ |__/|__/ \____//_/ /_/ \__,_/(_)" -echo "" diff --git a/bootstrap.sh b/bootstrap.sh index ab9d060..8c3bd19 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,4 +1,59 @@ -#!/usr/bin/env bash +#!/bin/bash + +# TODO Create a link(~/.bash_profile) linking to file(~/dotfiles/.bash_profile) +ln -s ~/dotfiles/.bash_profile ~/.bash_profile +ln -s ~/dotfiles/.bash_prompt ~/.bash_prompt +ln -s ~/dotfiles/.bash_bin ~/.bash_bin +ln -s ~/dotfiles/.bash_k8s ~/.bash_k8s +ln -s ~/dotfiles/.vimrc ~/.vimrc +ln -s ~/dotfiles/.bash_darwin ~/.bash_darwin +ln -s ~/dotfiles/.bash_linuxgnu ~/.bash_linuxgnu + +function install() { + echo "Which Operating System do you like?" + select os in Ubuntu LinuxMint Windows8 Windows7 WindowsXP; do + case $os in + "Ubuntu"|"LinuxMint") + echo "I also use $os." + ;; + "Windows8" | "Windows10" | "WindowsXP") + echo "Why don't you try Linux?" + ;; + *) + echo "Invalid entry." + break + ;; + esac + done +} + +# Install +# 1) install bash +# 2) chsh -> bash +# +# 0. Choose OS: macOS, CentOS, Ubuntu +# 1. Install Env +npm install -g hexo-cli +nrm +nvm + +# env +mkdir ~/dev +mkdir ~/bin + +# plugins +#cp -r .hammerspoon ~/.hammerspoon + +# debug tools: strace, gdb, cc, gcc + +# 2. Install alias, functions +# 3. Install ... +# 4. logfile + +# Uninstall +# TODO `rm` all + +######################################################## cd "$(dirname "${BASH_SOURCE}")" @@ -11,18 +66,18 @@ function doBootstrap() { --exclude "bootstrap.sh/" \ --exclude "README.md/" \ -avh --no-perms . ~ - + source ~/.bash_profile } if [ "$1" == "--force" -o "$1" == "-f" ]; then doBootstrap -else +else read -p "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1 echo "" if [[ $REPLY =~ ^[Yy]$ ]]]; then doBootstrap - fi + fi fi unset doBootstrap diff --git a/greetings.sh b/greetings.sh deleted file mode 100644 index 05a7907..0000000 --- a/greetings.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash - diff --git a/hammerspoon/bootstrap_hammerspoon.sh b/hammerspoon/bootstrap_hammerspoon.sh deleted file mode 100644 index 649fea5..0000000 --- a/hammerspoon/bootstrap_hammerspoon.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -cp -r .hammerspoon ~/.hammerspoon \ No newline at end of file