Last active
November 27, 2020 02:19
-
-
Save qins/2e1f5808ad68238168a01f64396e8aa8 to your computer and use it in GitHub Desktop.
bashrc for a new machine, or some temporary login, to avoid the clumsy primitive environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# .bashrc online | |
# one cmd usage: | |
# source <(curl -s https://gist.githubusercontent.com/qins/2e1f5808ad68238168a01f64396e8aa8/raw) | |
# If not running interactively, don't do anything | |
case $- in | |
*i*) ;; | |
*) return;; | |
esac | |
## other source | |
# Source global definitions | |
# cause bug on history and some where else | |
#if [ -f /etc/bashrc ]; then | |
# . /etc/bashrc | |
#fi | |
## Prompt style | |
# Define some colors first: | |
colorInit(){ | |
# color need [] | |
DARKGRAY='\[\e[1;30m\]' | |
red='\[\e[0;31m\]' | |
RED='\[\e[1;31m\]' | |
LIGHTRED='\[\e[1;31m\]' | |
green='\[\e[0;32m\]' | |
GREEN='\[\e[1;32m\]' | |
yellow='\[\e[0;33m\]' | |
YELLOW='\[\e[1;33m\]' | |
blue='\[\e[0;34m\]' | |
BLUE='\[\e[1;34m\]' | |
cyan='\[\e[0;36m\]' | |
CYAN='\[\e[1;36m\]' | |
white="\[\e[0;37m\]"; | |
NC='\[\e[0m\]' # No Color | |
} | |
colorInit | |
## in case of other shell as defalt | |
#alias sh="/bin/bash" | |
## bash prompt | |
PS1="[ " | |
PS1+="\[${yellow}\]\u"; # username | |
PS1+="\[${white}\] at "; | |
PS1+="\[${red}\]\h"; # host | |
PS1+="\[${white}\] in "; | |
PS1+="\[${green}\]\w\[${white}\]"; # working directory full path | |
PS1+=" ]" | |
PS1+="\n"; | |
PS1+="\$ \[${NC}\]"; # `$` (and reset color) | |
export PS1; | |
PS2="\[${yellow}\]→ \[${NC}\]"; | |
export PS2; | |
# init the environment (like a login) | |
alias sul="su --login" | |
## ssh shortcut | |
# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards | |
[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2- | tr ' ' '\n')" scp sftp ssh; | |
## hosts | |
HOSTALIASES=$HOME/.hosts | |
## file and dir | |
# dir | |
alias cd..="cd .." | |
alias cd-="cd -" | |
# soft link | |
alias lns="ln -s" | |
# file concise time log | |
# temp=${temp##.}: rm the head '.' | |
function cptime() { temp=$(basename $1);temp=${temp##.};cp $1 ${temp}_$(date +%Y%m%d_%H%M%S) ;} | |
function mkdirtime() { mkdir ${1}_$(date +%Y%m%d_%H%M%S) ;} | |
# list file | |
eval `dircolors` | |
alias lt="ls -t -r --color" | |
alias ll="ls -l -hS --color" | |
alias la="ls -tAr --color" | |
alias tree='tree --charset ASCII' | |
function lls() { ls -l -S -A -r -h --color $* | perl -lane 'next if $. == 1; print "$F[4]\t$F[5],$F[6],$F[7]\t$F[8]"'; } | |
function llt() { ls -l -t -A -r -h --color $* | perl -lane 'next if $. == 1; print "$F[5],$F[6],$F[7]\t$F[4]\t$F[8]"'; } | |
# detail file list | |
function lfd() { cat $* | xargs ls -l -t -A -r -h -d --color; } | |
# list full path | |
function lf() { echo -e "\n$PWD/$1\n"; ls $PWD/$1; } | |
# find file in . | |
function ff() { | |
if [ -z "$2" ]; then | |
dir='./' | |
else | |
dir=$2 | |
fi | |
if [ "$1" == "big" ] ; then | |
find $dir -type f -size +10M ; | |
elif [ "$1" == "time" ];then | |
find $dir -type f ! -newermt "2017-11-01 00:00:00"; | |
#find . -newermt "2013-01-01 00:00:00" ! -newermt "2013-01-02 00:00:00" | |
else | |
find $dir -type f -iname '*'$1'*' -ls ; | |
fi | |
} | |
## rm file, but backup | |
trash_dir="$HOME/.local/share/Trash/files" | |
function trash() { | |
now="$(date +%Y%m%d_%H%M%S)" | |
trash_now_dir=$trash_dir/$now | |
mkdir -p $trash_now_dir | |
mv --backup=t "$@" $trash_now_dir | |
} | |
function emptytrash() { | |
rm -rf $trash_dir | |
mkdir $trash_dir | |
} | |
### system control | |
# port usage | |
function portUsage() { | |
if [ -z "$1" ]; then | |
netstat -tln; | |
else | |
netstat -anp | grep $1; | |
fi | |
} | |
# file size | |
alias duc="du -shc" | |
# disk size | |
alias dfh="df -h" | |
## default file/dir permission | |
umask 027 | |
## language | |
#export LC_ALL=C | |
#export LC_CTYPE="zh_CN.UTF-8" | |
export LANG=en_US.UTF-8 | |
#export LC_CTYPE="en_US.UTF-8" | |
## kill crush | |
function pskill() { ps aux | grep $1 | perl -lane 'print $F[1]' | xargs kill; } | |
## grep process | |
function psgrep() { ps aux | grep $1; } | |
# editor | |
alias vi="vim" | |
export EDITOR=vi | |
[[ $- == *i* ]] && stty -ixon | |
# Update $LINES and $COLUMNS when terminal size changes. | |
shopt -s checkwinsize | |
# Enable extended globbing functionality. | |
shopt -s extglob | |
# minor errors in the spelling of a directory component in a cd command will be corrected | |
shopt -s cdspell | |
# Bash replaces directory names with the results of word expansion when performing filename completion | |
shopt -s direxpand | |
# Bash attempts spelling correction on directory names during word completion if the directory name initially supplied does not exist | |
shopt -s dirspell | |
# the pattern ‘**’ used in a filename expansion context will match all files and zero or more directories and subdirectories. | |
shopt -s globstar | |
# completion-ignore-case | |
case "$TERM" in | |
xterm*|rxvt*) | |
bind "set completion-ignore-case on" | |
;; | |
esac | |
# avoid execute clipboard content | |
bind "set enable-bracketed-paste on" | |
### utils | |
# count line number | |
alias wl="wc -l" | |
# count byte | |
function wcc() { echo $* | wc -c; } | |
# check data file | |
# make less more friendly for non-text input files, see lesspipe(1) | |
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" | |
alias les="less -S" | |
alias le="less -SN" | |
# ANSI color escape sequences | |
alias cles="less -RS" | |
function cole() { column -t -s $'\t' $* | less -SN; } | |
function csvcheck() { cat $1 | perl -lane 's/,/\t/g;print' | cole; } | |
alias head1="head -1" | |
alias egrep="egrep --color=auto" | |
alias sort="sort --parallel 8 --buffer-size=5G" | |
# history search | |
function hs() { history | grep --color $*; } | |
# Handy Extract Program. | |
function extract() | |
{ | |
if [ -f $1 ] ; then | |
case $1 in | |
*.tar.bz2) tar xvjf $1 ;; | |
*.tar.gz) tar xvzf $1 ;; | |
*.tar.xz) tar Jxvf $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 "'$1' cannot be extracted via >extract<" ;; | |
esac | |
else | |
echo "'$1' is not a valid file" | |
fi | |
} | |
### coding | |
# chmod all files 744 | |
alias cx="ls | perl -lane 'print if (/\.r$/i || /\.sh$/i || /\.pl$/i ||/\.py/i)' | xargs chmod 754" | |
# x server | |
export DISPLAY=:0.0 | |
### env setting | |
# home | |
PATH=".:$HOME:$HOME/bin:$HOME/.local/bin:$PATH" | |
# tools path | |
PATH="$HOME/tools/bin:$PATH" | |
# links to tools bin | |
function lnt() { ln -s $1 $HOME/tools/bin; } | |
# snap bin | |
PATH="/snap/bin:$PATH" | |
# local bin | |
PATH=$HOME/local/bin:$PATH | |
LD_LIBRARY_PATH="/usr/lib64/:/lib/x86_64-linux-gnu/:$HOME/tools/lib/:$LD_LIBRARY_PATH:$HOME/.local/lib/lib/" | |
export LD_LIBRARY_PATH | |
export PATH |
Author
qins
commented
Nov 27, 2020
- shorten url
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment