Last active
May 21, 2023 12:40
-
-
Save rnyrnyrny/99c73c7c393522fbb75939149904dda9 to your computer and use it in GitHub Desktop.
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: executed by bash(1) for non-login shells. | |
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) | |
# for examples | |
# test | |
# If not running interactively, don't do anything | |
case $- in | |
*i*) ;; | |
*) return;; | |
esac | |
# don't put duplicate lines or lines starting with space in the history. | |
# See bash(1) for more options | |
HISTCONTROL=ignoreboth | |
# append to the history file, don't overwrite it | |
shopt -s histappend | |
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) | |
HISTSIZE=1000 | |
HISTFILESIZE=10000 | |
# check the window size after each command and, if necessary, | |
# update the values of LINES and COLUMNS. | |
shopt -s checkwinsize | |
# If set, the pattern "**" used in a pathname expansion context will | |
# match all files and zero or more directories and subdirectories. | |
#shopt -s globstar | |
# make less more friendly for non-text input files, see lesspipe(1) | |
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" | |
# set variable identifying the chroot you work in (used in the prompt below) | |
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then | |
debian_chroot=$(cat /etc/debian_chroot) | |
fi | |
# set a fancy prompt (non-color, unless we know we "want" color) | |
case "$TERM" in | |
xterm-color|*-256color*) color_prompt=yes;; | |
esac | |
# uncomment for a colored prompt, if the terminal has the capability; turned | |
# off by default to not distract the user: the focus in a terminal window | |
# should be on the output of commands, not on the prompt | |
#force_color_prompt=yes | |
if [ -n "$force_color_prompt" ]; then | |
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then | |
# We have color support; assume it's compliant with Ecma-48 | |
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such | |
# a case would tend to support setf rather than setaf.) | |
color_prompt=yes | |
else | |
color_prompt= | |
fi | |
fi | |
if [ "$color_prompt" = yes ]; then | |
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
else | |
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
fi | |
unset color_prompt force_color_prompt | |
# If this is an xterm set the title to user@host:dir | |
case "$TERM" in | |
xterm*|rxvt*) | |
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" | |
;; | |
*) | |
;; | |
esac | |
# enable color support of ls and also add handy aliases | |
if [ -x /usr/bin/dircolors ]; then | |
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
alias ls='ls --color=auto' | |
#alias dir='dir --color=auto' | |
#alias vdir='vdir --color=auto' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
fi | |
# colored GCC warnings and errors | |
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' | |
# some more ls aliases | |
alias ll='ls -l' | |
alias la='ls -A' | |
alias l='ls -CF' | |
# Alias definitions. | |
# You may want to put all your additions into a separate file like | |
# ~/.bash_aliases, instead of adding them here directly. | |
# See /usr/share/doc/bash-doc/examples in the bash-doc package. | |
if [ -f ~/.bash_aliases ]; then | |
. ~/.bash_aliases | |
fi | |
# enable programmable completion features (you don't need to enable | |
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile | |
# sources /etc/bash.bashrc). | |
if ! shopt -oq posix; then | |
if [ -f /usr/share/bash-completion/bash_completion ]; then | |
. /usr/share/bash-completion/bash_completion | |
elif [ -f /etc/bash_completion ]; then | |
. /etc/bash_completion | |
fi | |
fi | |
# rny | |
ipL=$(ip a | grep inet | grep eth0 | awk '{{print $2}}' | awk -F '/' '{{print $1}}' | head -n 1) | |
if [[ ${JUNEST_ENV} == 1 ]]; then | |
ipL+="[junest]" | |
fi | |
if [[ ${EUID} == 0 ]] ; then | |
PS1="\[\033[01;31m\]root@${ipL}\[\033[01;34m\]:\w \[\033[01;33m\]\$\[\033[00m\] " | |
else | |
PS1="\[\033[01;32m\]\u@${ipL}\[\033[01;34m\]:\w \[\033[01;33m\]\$\[\033[00m\] " | |
fi | |
## wsl2 | |
if [[ "$(< /proc/sys/kernel/osrelease)" == *microsoft* ]]; then | |
export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*') | |
## clash proxy | |
alias setproxy='export all_proxy="http://${hostip}:7890";export http_proxy="$all_proxy";export https_proxy="$all_proxy";curl ip.sb;' | |
alias unsetproxy='unset all_proxy;unset http_proxy;unset https_pxory;curl ip.sb;' | |
fi | |
export EDITOR=/usr/bin/nvim | |
export LANG="en_US.UTF-8" | |
export LESS='-I -M -R' | |
export SYSTEMD_PAGER=less | |
export PROMPT_COMMAND="history -a; history -n" | |
#https://gist.github.com/junegunn/8b572b8d4b5eddd8b85e5f4d40f17236 | |
is_in_git_repo() { | |
git rev-parse HEAD > /dev/null 2>&1 | |
} | |
fzf-down() { | |
fzf --height 50% "$@" --border | |
} | |
gb() { | |
is_in_git_repo || return | |
git branch -a --color=always | grep -v '/HEAD\s' | sort | | |
fzf-down --ansi --multi --tac --preview-window right:70% \ | |
--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1) -- | head -'$LINES | | |
sed 's/^..//' | cut -d' ' -f1 | | |
sed 's#^remotes/##' | |
} | |
gf() { | |
is_in_git_repo || return | |
git -c color.status=always status --short | | |
fzf-down -m --ansi --nth 2..,.. \ | |
--preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -500' | | |
cut -c4- | sed 's/.* -> //' | |
} | |
gh() { | |
is_in_git_repo || return | |
git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always | | |
fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \ | |
--header 'Press CTRL-S to toggle sort' \ | |
--preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | head -1 | xargs git show --color=always | head -'$LINES | | |
grep -o "[a-f0-9]\{7,\}" | head -1 | |
} | |
gr() { | |
is_in_git_repo || return | |
git remote -v | awk '{print $1 "\t" $2}' | uniq | | |
fzf-down --tac \ | |
--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" --remotes={1} | head -200' | | |
cut -d$'\t' -f1 | |
} | |
gt() { | |
is_in_git_repo || return | |
git tag --sort -version:refname | | |
fzf-down --multi --preview-window right:70% \ | |
--preview 'git show --color=always {} | head -'$LINES | |
} | |
[ -f /usr/share/fzf/completion.bash ] && . /usr/share/fzf/completion.bash | |
[ -f /usr/share/fzf/key-bindings.bash ] && . /usr/share/fzf/key-bindings.bash | |
if [ -f /usr/bin/fzf ]; then | |
export FZF_DEFAULT_OPTS='--height 50% --layout=reverse --border' | |
FZF_PREVIEW_OPT='(rougify {} || | |
highlight -O ansi -l {} || | |
cat {} || | |
tree -C {}) 2> /dev/null | head -50' | |
#export FZF_CTRL_T_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'" | |
export FZF_CTRL_T_OPTS="--preview '$FZF_PREVIEW_OPT'" | |
# Options to fzf command | |
export FZF_COMPLETION_OPTS='+c -x' | |
export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'" | |
if [ -f /usr/bin/fd ]; then | |
# Use fd (https://github.com/sharkdp/fd) instead of the default find | |
# command for listing path candidates. | |
# - The first argument to the function ($1) is the base path to start traversal | |
# - See the source code (completion.{bash,zsh}) for the details. | |
_fzf_compgen_path() { | |
fd --hidden --follow --exclude ".git" . "$1" | |
} | |
# Use fd to generate the list for directory completion | |
_fzf_compgen_dir() { | |
fd --type d --hidden --follow --exclude ".git" . "$1" | |
} | |
fi | |
fi | |
ex () | |
{ | |
if [ -f $1 ] ; then | |
case $1 in | |
*.tar.bz2) tar xjf $1 ;; | |
*.tar.gz) tar xzf $1 ;; | |
*.bz2) bunzip2 $1 ;; | |
*.rar) unrar x $1 ;; | |
*.gz) gunzip $1 ;; | |
*.tar) tar xf $1 ;; | |
*.tbz2) tar xjf $1 ;; | |
*.tgz) tar xzf $1 ;; | |
*.zip) unzip $1 ;; | |
*.Z) uncompress $1;; | |
*.7z) 7z x $1 ;; | |
*) echo "'$1' cannot be extracted via ex()" ;; | |
esac | |
else | |
echo "'$1' is not a valid file" | |
fi | |
} | |
# rny end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment