├── .bash_profile ├── .gitignore ├── .travis.yml ├── README.md ├── install.sh └── scripts ├── color.js └── history.js /.bash_profile: -------------------------------------------------------------------------------- 1 | ## color 2 | export CLICOLOR=1 3 | export TERM=xterm-256color 4 | export LSCOLORS=gxfxcxdxbxegedabagacad 5 | 6 | ## aliases 7 | alias ls="ls -a -G" 8 | alias update="curl -o- https://raw.githubusercontent.com/xudafeng/bash/master/install.sh | bash && source ~/.bash_profile" 9 | alias his="history | node ~/.bash/scripts/history.js" 10 | alias clean="git branch | xargs git branch -D" 11 | alias gitpull="git pull" 12 | alias python="python3" 13 | 14 | ## visual code 15 | VISUALSTUDIOCODE="/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" 16 | if [[ -f $VISUALSTUDIOCODE ]]; then 17 | alias code="\"$VISUALSTUDIOCODE\" ." 18 | fi 19 | 20 | ## cursor 21 | CURSOR_CODE="/Applications/Cursor_remove.app/Contents/Resources/app/bin/code" 22 | if [[ -f $CURSOR_CODE ]]; then 23 | alias code="\"$CURSOR_CODE\" ." 24 | fi 25 | 26 | ## git branch 27 | get_git_branch() { 28 | echo $(git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/') | node ~/.bash/scripts/color.js --color red 2>/dev/null 29 | } 30 | 31 | ## node 32 | get_node_version() { 33 | local node_version 34 | node_version=$(node -v 2>/dev/null) 35 | echo ${node_version:1} | node ~/.bash/scripts/color.js --color cyan 2>/dev/null 36 | } 37 | 38 | # nvm 39 | export NVM_NODEJS_ORG_MIRROR="http://npm.taobao.org/dist" 40 | export NVM_DIR="$HOME/.nvm" 41 | [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" 42 | [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion 43 | 44 | # PS 45 | PS1="\u@node\$(get_node_version):\w\$(get_git_branch)\n➟ " 46 | export PS1 47 | export PKG_CONFIG_PATH="/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig/" 48 | 49 | ## local bash profile 50 | LOCAL_BASH_PROFILE="$HOME/.local_bash_profile" 51 | if [[ -f $LOCAL_BASH_PROFILE ]]; then 52 | . $LOCAL_BASH_PROFILE 53 | fi 54 | 55 | ## Android SDK 56 | ANDROID_HOME=$HOME"/Library/Android/sdk" 57 | if [ -d $ANDROID_HOME ]; then 58 | export ANDROID_HOME 59 | export PATH=$PATH:$ANDROID_HOME/build-tools/32.0.0/:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools/:$ANDROID_HOME/ 60 | fi 61 | 62 | ## PKG_CONFIG 63 | export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig 64 | 65 | ## homebrew 66 | export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles 67 | eval "$(/opt/homebrew/bin/brew shellenv)" 68 | 69 | ## flutter 70 | # export PATH=$PATH:/usr/local/opt/flutter/bin 71 | 72 | ## autojump 73 | [ -f /opt/homebrew/etc/profile.d/autojump.sh ] && . /opt/homebrew/etc/profile.d/autojump.sh 74 | 75 | ## direnv 76 | eval "$(direnv hook bash)" 77 | 78 | ## java 79 | export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)" 80 | 81 | export CXXFLAGS="-std=c++11" 82 | export CFLAGS="-std=c++11" 83 | 84 | ## mysql 85 | MYSQL_VERSION="8.0" 86 | mysql_path="$(brew --prefix mysql@$MYSQL_VERSION 2>/dev/null)/bin" 87 | if [ -n "$mysql_path" ]; then 88 | export PATH="$mysql_path:$PATH" 89 | fi 90 | 91 | ## uv 92 | # curl -LsSf https://astral.sh/uv/install.sh | sh 93 | source $HOME/.local/bin/env -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.sw* 3 | *.un~ 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | node_js: 4 | - 8 5 | script: 6 | - node ./scripts/color.js & 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # My bash script. 2 | 3 | [![build status][travis-image]][travis-url] 4 | 5 | [travis-image]: https://img.shields.io/travis/xudafeng/bash.svg 6 | [travis-url]: https://travis-ci.org/xudafeng/bash 7 | 8 | ```bash 9 | curl -o- https://raw.githubusercontent.com/xudafeng/bash/master/install.sh | bash 10 | ``` 11 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo Install Starting … 4 | rm -rf ~/.bash ~/.bash_profile 5 | git clone https://github.com/xudafeng/bash.git --depth=1 ~/.bash 6 | ln -s ~/.bash/.bash_profile ~/.bash_profile 7 | echo Done. 8 | -------------------------------------------------------------------------------- /scripts/color.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const stream = require('stream'); 4 | 5 | let color = 'red'; 6 | 7 | if (process.argv.length > 2) { 8 | color = process.argv[process.argv.length - 1]; 9 | } 10 | 11 | const colorWrapper = (string, color) => { 12 | switch (color) { 13 | case 'red': 14 | return `\u001b[31m${string}\u001b[0m`; 15 | case 'yellow': 16 | return `\u001b[33m${string}\u001b[0m`; 17 | case 'green': 18 | return `\u001b[32m${string}\u001b[0m`; 19 | case 'purple': 20 | return `\u001b[34m${string}\u001b[0m`; 21 | case 'pink': 22 | return `\u001b[35m${string}\u001b[0m`; 23 | case 'cyan': 24 | return `\u001b[36m${string}\u001b[0m`; 25 | case 'blue': 26 | return `\u001b[37m${string}\u001b[0m`; 27 | default: 28 | return `\u001b[37m${string}\u001b[0m`; 29 | } 30 | }; 31 | 32 | function ColorStream(options) { 33 | stream.Writable.call(this, options); 34 | } 35 | 36 | ColorStream.prototype = Object.create(stream.Writable.prototype, { 37 | constructor: { 38 | value: ColorStream 39 | } 40 | }); 41 | 42 | ColorStream.prototype._write = function(chunk, encoding, callback) { 43 | process.stdout.write(colorWrapper(chunk.toString().trim(), color)); 44 | callback(); 45 | }; 46 | 47 | process.stdin.pipe(new ColorStream()); 48 | -------------------------------------------------------------------------------- /scripts/history.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const stream = require('stream'); 4 | 5 | const keywords = process.argv[2]; 6 | const showLength = process.argv[3]; 7 | 8 | const BLANK = ' '; 9 | 10 | function Selector(options = {}) { 11 | this.keywords = options.keywords; 12 | this.showLength = options.showLength; 13 | this.list = options.list; 14 | this.init(); 15 | } 16 | 17 | Selector.prototype.init = function() { 18 | this.format(); 19 | }; 20 | 21 | Selector.prototype.format = function() { 22 | this.list = this.list.split('\n'); 23 | this.list = this.list.map(item => { 24 | const arr = item.split(/\s+/g); 25 | arr.shift(); 26 | arr.shift(); 27 | return arr.join(BLANK); 28 | }); 29 | this.list.pop(); 30 | this.list = [...new Set(this.list)]; 31 | }; 32 | 33 | Selector.prototype.render = function() { 34 | const hightlight = `\u001b[31m${this.keywords}\u001b[0m`; 35 | const result = this.list.filter(item => { 36 | return !!~item.toLowerCase().indexOf(this.keywords.toLowerCase()); 37 | }).slice(0, this.showLength).map((item, key) => { 38 | return `${key} ${item.replace(this.keywords, hightlight)}`; 39 | }); 40 | 41 | if (result.length) { 42 | console.log('\n'); 43 | console.log(result.join('\n\n')); 44 | console.log('\n'); 45 | } 46 | }; 47 | 48 | function HistoryStream(options) { 49 | stream.Writable.call(this, options); 50 | } 51 | 52 | HistoryStream.prototype = Object.create(stream.Writable.prototype, { 53 | constructor: { 54 | value: HistoryStream 55 | } 56 | }); 57 | 58 | HistoryStream.prototype._write = function(chunk, encoding, callback) { 59 | const length = parseInt(showLength || 5, 10); 60 | const s = new Selector({ 61 | keywords, 62 | showLength: length, 63 | list: chunk.toString().trim() 64 | }); 65 | s.render(); 66 | callback(); 67 | }; 68 | 69 | process.stdin.pipe(new HistoryStream()); 70 | --------------------------------------------------------------------------------