├── .gitconfig ├── .vimrc ├── .zshrc ├── .zshrc_mac ├── README.md ├── init.sh ├── neo_fetch_config.conf ├── tools ├── 3p.sh ├── gsync.sh ├── snp.sh └── v2ray_install.sh └── utils ├── distro.sh ├── err.sh └── header.sh /.gitconfig: -------------------------------------------------------------------------------- 1 | [user] 2 | name = Your Name 🚀 3 | email = youremail 4 | [init] 5 | defaultBranch = main 6 | [fetch] 7 | # Auto rm remote-tracking refs that no longer exist on the remote 8 | prune = true 9 | [push] 10 | default = current 11 | autoSetupRemote = true 12 | [alias] 13 | # list out all aliases (`!` runs normal shell commands) 14 | la = ! git config -l | grep -E "^alias" 15 | 16 | # common 17 | st = status 18 | sw = switch 19 | pl = log --pretty='%Cgreen%h %Creset%an %ar %C(cyan)<%s>' # pretty log. see: https://git-scm.com/docs/pretty-formats 20 | dac = ! git clean -df && git restore . # discard all changes (discard untracked files & dirs, changes in working dir) 21 | pick = cherry-pick # pick commit(s) 22 | 23 | # commit related 24 | cm = commit -m 25 | ca = commit --amend 26 | 27 | # stash related 28 | sl = stash list 29 | sa = stash apply 30 | sp = stash pop 31 | sm = stash -m 32 | 33 | # restore related 34 | r = restore # discard changes in working directory 35 | rs = restore --staged # unstage file(s) 36 | 37 | # diff related 38 | d = diff # diff with changes working directory 39 | ds = diff --staged # diff with staged changes 40 | dst = diff --stat 41 | 42 | # branch related 43 | br = for-each-ref refs/heads/ --sort=-committerdate \ 44 | --format=\"%(committerdate:short) %(color:red)%(objectname:short) %(if)%(HEAD)%(then)%(color:cyan)* %(else)%(color:yellow)%(end)%(refname:short)%(color:reset) (%(color:green)%(committerdate:relative)%(color:reset))\" 45 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | " set encoding to utf-8 2 | set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 3 | set termencoding=utf-8 4 | set encoding=utf-8 5 | 6 | " remap esc to jk in insert mode 7 | imap jk 8 | 9 | " syntax highlighting 10 | syntax on 11 | 12 | " search settings 13 | set incsearch 14 | set ignorecase 15 | set smartcase 16 | 17 | " scroll the screen if distance(cur_line, bottom) < 8 18 | set scrolloff=8 19 | 20 | " show absolute & relative line number 21 | set number 22 | set relativenumber 23 | 24 | " Use a line cursor within insert mode and a block cursor everywhere else. 25 | " 26 | " Reference chart of values: 27 | " Ps = 0 -> blinking block. 28 | " Ps = 1 -> blinking block (default). 29 | " Ps = 2 -> steady block. 30 | " Ps = 3 -> blinking underline. 31 | " Ps = 4 -> steady underline. 32 | " Ps = 5 -> blinking bar (xterm). 33 | " Ps = 6 -> steady bar (xterm). 34 | let &t_SI = "\e[5 q" " insert mode 35 | let &t_EI = "\e[2 q" " other modes 36 | 37 | " set tab space to 2 38 | set tabstop=2 39 | set shiftwidth=2 40 | 41 | " using vim-plug as vim plugin manager 42 | call plug#begin('~/.vim/plugged') 43 | 44 | call plug#end() 45 | -------------------------------------------------------------------------------- /.zshrc: -------------------------------------------------------------------------------- 1 | # util functions 2 | 3 | function header() { 4 | echo -e "\n** $1 **\n" 5 | } 6 | 7 | function err() { 8 | echo "$1" >&2 9 | } 10 | 11 | function getDistro() { 12 | local distro 13 | if [[ -e /etc/os-release ]]; then 14 | # Linux has /etc/os-release file 15 | # shellcheck disable=SC1091 16 | source /etc/os-release 17 | # /etc/os-release when sourced, will add the $NAME environment variable 18 | if echo "$NAME" | grep -iq ubuntu; then 19 | distro="Ubuntu" 20 | fi 21 | elif [[ $(uname) == "Darwin" ]]; then 22 | distro="macOS" 23 | else 24 | echo "Sorry, this script only support Ubuntu & macOS" 25 | exit 1 26 | fi 27 | echo "$distro" 28 | } 29 | 30 | # set zsh to use vi mode & remap escape key to jk 31 | bindkey -v 32 | bindkey jk vi-cmd-mode 33 | # set terminal tab-width to 2 columns 34 | tabs -2 35 | 36 | # ---------- global variables ---------- 37 | 38 | # remote repo addr 39 | repoAddr="https://realrz.com/shell-scripts" 40 | 41 | distro="$(getDistro)" 42 | export distro 43 | 44 | # terminal prompt (%f means reset color; %F{color} format color, just google "shell format color" for available colors) 45 | # ref: https://zsh-prompt-generator.site/ 46 | PROMPT="%F{yellow}%h%f %F{magenta}%~%f 🚀 " 47 | RPROMPT="%(?.%F{green}.%F{red})%?%f" 48 | 49 | # locale setting 50 | export LC_ALL="en_US.UTF-8" 51 | export LANG="zh_CN.UTF-8" 52 | 53 | # ---------- end of global variables ---------- 54 | 55 | # set vim as default editor 56 | if command -v vim &> /dev/null; then 57 | if [[ "$distro" == "Ubuntu" ]]; then 58 | update-alternatives --set editor /usr/bin/vim.basic 59 | else 60 | # export EDITOR as environment variable 61 | # this will set vim as default editor on macOS 62 | EDITOR=$(command -v vim) 63 | export EDITOR 64 | fi 65 | fi 66 | 67 | setopt autocd # change directory just by typing its name 68 | 69 | if [ -e ~/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then 70 | source ~/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 71 | fi 72 | 73 | # ---- aliases and functions ---- 74 | 75 | # cs: config system 76 | alias cs="bash <(curl -sL $repoAddr/init.sh)" 77 | 78 | # edit/source zsh config 79 | alias zc='vim ~/.zshrc' 80 | alias sz="source ~/.zshrc" 81 | # edit vim config 82 | alias vc="vim ~/.vimrc" 83 | 84 | alias b="cd .." 85 | alias c='clear' 86 | alias v='vim' 87 | alias his='history -d' 88 | alias wh='which' 89 | alias sc="shellcheck --shell=bash" 90 | 91 | # long formated ls sort by file size 92 | alias lls="ls -AlhS" 93 | 94 | # gh for go home 95 | alias gh="cd ~" 96 | 97 | # pubip & myip for public ip address 98 | # ifconfig.me & ident.me both provide this type of service 99 | alias pubip="curl -sL -sL https://ifconfig.me" 100 | alias myip="curl -sL https://v4.ident.me" 101 | 102 | # -------- git related --------- 103 | 104 | # gdb: git delete branch (by regex) 105 | function gdb () { 106 | # basic check 107 | if ! git status &> /dev/null 108 | then 109 | echo "You are not inside a git repo" 110 | return 1 111 | fi 112 | 113 | # get repo type (local or remote) 114 | echo "1. Local branch(es)" 115 | echo "2. Remote branch(es)" 116 | echo -n "Which type of branch(es) to delete(1 or 2): " 117 | read -r repo_type 118 | if [[ "$repo_type" -ne 1 && "$repo_type" -ne 2 ]]; then 119 | echo "Only 1 or 2 are permitted" 120 | return 1 121 | fi 122 | 123 | if [[ "$repo_type" -eq 2 ]]; then 124 | # get remote name 125 | echo 126 | git remote 127 | echo 128 | echo -n "Which remote is your target: " 129 | read -r remote 130 | if ! git remote | grep -q "$remote" 131 | then 132 | echo "No such remote" 133 | return 1 134 | fi 135 | fi 136 | 137 | # list out all branches 138 | echo 139 | if [[ "$repo_type" -eq 1 ]]; then 140 | all_branches_count=$(git branch | grep -c '^') 141 | echo "Found $all_branches_count local branches" 142 | echo 143 | git branch 144 | else 145 | # fetching branches for that remote 146 | echo "Fetching branches on $remote" 147 | echo 148 | git fetch --prune 149 | all_branches=$(git branch -a | grep -i "remotes/${remote}") 150 | all_branch_count=$(echo -n "$all_branches" | grep -c '^') 151 | echo "Found $all_branch_count branches on ${remote}" 152 | echo 153 | echo "$all_branches" 154 | fi 155 | 156 | # ask for branch regex 157 | echo 158 | echo -n "Branch regex (no need to surround it with //): " 159 | read -r branch_regex 160 | 161 | # get branches to delete 162 | if [[ "$repo_type" -eq 1 ]]; then 163 | branches=$(git branch | awk -v pattern="$branch_regex" '$1 ~ pattern {print $1}') 164 | else 165 | branches=$(git branch -a | grep -i "remotes/${remote}" | awk -v pattern="$branch_regex" -F'/' '$3 ~ pattern {print $3}') 166 | fi 167 | branch_count=$(echo -n "$branches" | grep -c '^') 168 | if [[ "$branch_count" -eq 0 ]] 169 | then 170 | echo "No branch matched" 171 | return 1 172 | fi 173 | echo 174 | echo "$branch_count branches matched: " 175 | echo 176 | echo "$branches" 177 | echo 178 | 179 | # ask for confirmation 180 | echo -n "Delete all branches listed above? (Y/N): " 181 | read -r confirm 182 | echo 183 | if ! [[ "$confirm" =~ ^[Yy][Es]?[Ss]? ]] 184 | then 185 | echo "Aborted" 186 | return 187 | fi 188 | 189 | # delete branch one by one 190 | while IFS= read -r branch 191 | do 192 | if [[ "$repo_type" -eq 1 ]]; then 193 | git branch -D "$branch" 194 | else 195 | git push "$remote" --delete "$branch" 196 | fi 197 | done <<< "$branches" 198 | 199 | echo 200 | echo "DONE" 201 | } 202 | 203 | 204 | # -------- end of git related ------ 205 | 206 | # list the PATH environment variable(one path per row, sort by path length) 207 | lpath() { 208 | echo "$PATH" | awk -v RS=":" '{print length, $1}' | sort -n -s | awk '{print $2}' 209 | } 210 | 211 | # mcd for mkdir && cd 212 | mcd() { 213 | mkdir "$1" && cd "$1" || return 214 | } 215 | 216 | # today in format "YYYY-MM-DD" 217 | today () { 218 | if [[ "$distro" == "macOS" ]]; then 219 | date "+%Y-%m-%d" 220 | else 221 | date --rfc-3339=date 222 | fi 223 | } 224 | 225 | # how much disk space is left 226 | space () { 227 | df -H | awk ' 228 | NR==1 { 229 | for (i=1; i<=NF; i++) { 230 | if ($i == "Size") sizeIndex = i 231 | if ($i == "Avail") availIndex = i 232 | if ($i == "Mounted") mountedIndex = i 233 | } 234 | } 235 | $mountedIndex=="/" { 236 | print $availIndex, "of", $sizeIndex, "is available" 237 | } 238 | ' 239 | } 240 | 241 | # print out directory size 242 | dirsize () { 243 | local depthOption="--max-depth" 244 | if [[ "$distro" == "macOS" ]]; then 245 | depthOption="-d" 246 | fi 247 | du -h "$depthOption"=1 "$1" | tail -1 | awk '{print $1}' 248 | } 249 | 250 | # sop: scan open port 251 | sop () { 252 | # better use nmap 253 | # although you could use netstat or ss, they work differently under macOS & linux 254 | # -p- means scan all ports (1-65535) 255 | nmap -p- localhost | grep "/tcp" | awk -F'/' '{print $1}' 256 | } 257 | 258 | # 3p: program, pid, port 259 | alias 3p="bash <(curl -sL $repoAddr/tools/3p.sh)" 260 | 261 | # print file as binary string 262 | binary () { 263 | xxd -b -c 1 "$1" \ 264 | | awk '{print $2}' \ 265 | | tr -d '\n' && echo 266 | } 267 | 268 | # print file as hex string 269 | hex () { 270 | xxd -c 1 "$1" \ 271 | | awk '{print $2}' \ 272 | | tr -d '\n' && echo 273 | } 274 | 275 | # print out cool emoji 276 | smile () { 277 | # f09f988e is utf-8 hex for emoji(smiling face with sunglasses) 278 | # 0a is ascii/utf-8 for line feed 279 | echo -n "f09f988e0a" | xxd -r -p 280 | } 281 | 282 | # network info for ubuntu 283 | ni_ubuntu () { 284 | local hwinfo=$(sudo lshw -c network) 285 | 286 | # type: Wi-Fi or Ethernet 287 | echo -n "type: " 288 | local desp=$(echo "$hwinfo" | grep 'description') 289 | if echo "$desp" | grep -Ei 'wireless' &> /dev/null; then 290 | echo "Wi-Fi" 291 | else 292 | echo "Ethernet" 293 | fi 294 | 295 | # interface 296 | echo -n "interface: " 297 | local intfname=$(echo "$hwinfo" | grep 'logical name' | awk '{print $3}') 298 | echo "$intfname" 299 | 300 | # mac addr 301 | echo -n "MAC addr: " 302 | echo "$hwinfo" | grep 'serial' | awk '{print $2}' 303 | echo 304 | 305 | echo "**Netowrk Info**" 306 | echo 307 | 308 | echo -n "hostname: " 309 | hostname 310 | 311 | echo -n "private IP: " 312 | ifconfig "$intfname" | awk '/inet /{print $2}' 313 | 314 | # ubuntu uses systemd-resolve 315 | echo -n "dns server: " 316 | resolvectl status | grep -i "current dns server" | awk -F': ' '{print $2}' 317 | 318 | echo -n "gateway: " 319 | ip route | grep default | awk 'NR==1{print $3}' 320 | 321 | echo -n "public IP: " 322 | curl -sL v4.ident.me 323 | echo 324 | } 325 | 326 | # network info for mac 327 | ni_mac () { 328 | local ports=$(networksetup -listallhardwareports) 329 | # Wi-Fi info 330 | local wifi_intf=$(echo "$ports" | awk '/Wi-Fi/{getline; print $2}') 331 | if [[ -n "$wifi_intf" ]] 332 | then 333 | local wifi_ip=$(ipconfig getifaddr "$wifi_intf") 334 | if [[ -n "$wifi_ip" ]] 335 | then 336 | echo "** Wi-Fi **" 337 | echo "interface: ${wifi_intf}" 338 | local wifi_mac=$(echo "$ports" | awk '/Wi-Fi$/{getline; getline; print $3}') 339 | echo "MAC addr: ${wifi_mac}" 340 | echo "private IP: $wifi_ip" 341 | echo 342 | fi 343 | fi 344 | 345 | # Ethernet info 346 | local eth_intf=$(echo "$ports" | awk '/Ethernet$/{getline; print $2}') 347 | if [[ -n "$eth_intf" ]] 348 | then 349 | local eth_ip=$(ipconfig getifaddr "$eth_intf") 350 | if [[ -n "$eth_ip" ]] 351 | then 352 | echo "** Ethernet **" 353 | echo "interface: ${eth_intf}" 354 | local eth_mac=$(echo "$ports" | awk '/Ethernet$/{getline; getline; print $3}') 355 | echo "MAC addr: ${eth_mac}" 356 | echo "private IP: $eth_ip" 357 | echo 358 | fi 359 | fi 360 | # hostname, nameserver, public ip 361 | echo "hostname: $(hostname)" 362 | scutil --dns | grep nameserver | sort | uniq 363 | echo "public ip: $(curl -sL v4.ident.me)" 364 | } 365 | 366 | # network info 367 | 368 | ni () { 369 | if [[ "$distro" == "Ubuntu" ]]; then 370 | ni_ubuntu 371 | else 372 | ni_mac 373 | fi 374 | } 375 | 376 | # template generator 377 | template () { 378 | echo "1) html" 379 | echo "2) react FC" 380 | echo -n "Enter number to generate template: " 381 | read -r option 382 | echo 383 | 384 | # template preset 385 | local html 386 | local rfc 387 | html=$( 388 | cat << EOF 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | EOF 401 | ) 402 | rfc=$( 403 | cat << EOF 404 | import { FC } from 'react' 405 | 406 | interface IProps {} 407 | 408 | const Component: FC = () => { 409 | return ( 410 |
411 | ) 412 | } 413 | 414 | export default Component 415 | EOF 416 | ) 417 | # echo to stdout 418 | if [[ "$option" -eq 1 ]]; then 419 | echo "$html" 420 | elif [[ "$option" -eq 2 ]]; then 421 | echo "$rfc" 422 | else 423 | echo "wrong option" 424 | return 1 425 | fi 426 | } 427 | 428 | # mac specific settins 429 | if [[ -e ~/.zshrc_mac ]]; then 430 | # shellcheck source=/dev/null 431 | source ~/.zshrc_mac 432 | fi 433 | 434 | # private settings, DO NOT make it public 435 | # things like aliases for ssh into your vps, shell http/https proxy settings, added path to the PATH variable 436 | if [[ -e ~/.zshrc_private ]]; then 437 | # shellcheck source=/dev/null 438 | source ~/.zshrc_private 439 | fi 440 | -------------------------------------------------------------------------------- /.zshrc_mac: -------------------------------------------------------------------------------- 1 | # mac only settings 2 | 3 | vol () { 4 | osascript -e "set volume output volume $1" 5 | } 6 | 7 | notify () { 8 | osascript -e "display notification \"$2\" with title \"$1\"" 9 | } 10 | 11 | trash () { 12 | file="$1" 13 | # in order to operate inside ~/.Trash 14 | # you'd have to give your Terminal app Full Disk Access in Security & Privacy 15 | mv "$file" ~/.Trash 16 | } 17 | 18 | # print name server 19 | ns () { 20 | scutil --dns | grep nameserver | awk '{print $3}' | sort | uniq 21 | } 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## script & tools for a better terminal experience 🚀 2 | 3 | #### System support 4 | 5 | - macOS 12+ 6 | - Ubuntu 18+ 7 | 8 | #### How to install 9 | 10 | `bash <(curl -sL https://raw.githubusercontent.com/librz/shell-scripts/main/init.sh)` 11 | 12 | #### Important notice 13 | 14 | This script will change ssh listening port from the default `22` to `9000`, this is a delibrate choice to help avoid malicious attempts to scan/break into your VPS. 15 | 16 | As of 2023, many VPS providers enable firewalla by default & only allow 22 in their default setting. You need to make sure port `9000` is open before running this script on your server, else there's no way to ssh into your server & you have to do full reinstall. 17 | 18 | On Ubuntu, the firewall manager is `ufw`, you can check its status using `ufw status`. I personally would turn the firewall off by running `ufw disable`. 19 | 20 | You can use namp to check whether a specific port is open on remote machine: `nmap -Pn {ip} -n {port}` 21 | 22 | #### Disclaimer 23 | 24 | This repo is open source thus 100% open for verification and risk checking. 25 | 26 | That being said, running `init.sh` requires **sudo** access, do it at your own risk. 27 | -------------------------------------------------------------------------------- /init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # linux init script, run this to set up 4 | # OS support: Ubuntu, macOS 5 | # usage: bash <(curl -sL https://realrz.com/shell-scripts/init.sh) 6 | 7 | # this script is idempotent, in another word, running it multiple times has the same effect as running it once 8 | # so when this script is updated, just execute it again 9 | 10 | 11 | # remote repo address 12 | repoAddr="https://realrz.com/shell-scripts" 13 | 14 | # utils functions 15 | 16 | function err() { 17 | echo "$1" >&2 18 | } 19 | 20 | function header() { 21 | echo -e "\n** $1 **\n" 22 | } 23 | 24 | function getDistro() { 25 | local distro 26 | if [[ -e /etc/os-release ]]; then 27 | # Linux has /etc/os-release file 28 | # shellcheck disable=SC1091 29 | source /etc/os-release 30 | # /etc/os-release when sourced, will add the $NAME environment variable 31 | if echo "$NAME" | grep -iq ubuntu; then 32 | distro="Ubuntu" 33 | fi 34 | elif [[ $(uname) == "Darwin" ]]; then 35 | distro="macOS" 36 | else 37 | echo "Sorry, this script only support Ubuntu & macOS" 38 | exit 1 39 | fi 40 | echo "$distro" 41 | } 42 | 43 | # check distro 44 | header "Checking distro" 45 | if ! distro=$(getDistro); then 46 | exit 1 47 | fi 48 | echo "You are running: $distro" 49 | 50 | # auto remove 51 | if [[ "$distro" == "Ubuntu" ]]; then 52 | header "Removing unnecessary pacakges using apt autoremove" 53 | yes | apt autoremove 54 | fi 55 | 56 | # install softwares 57 | header "Installing packages" 58 | if [[ "$distro" == "Ubuntu" ]]; then 59 | if apt update &>/dev/null && yes | apt install zsh vim git snapd curl tldr tree xxd net-tools sysstat nmap dnsutils neofetch lolcat shellcheck; then 60 | echo "success" 61 | else 62 | err "apt install failed" 63 | exit 2 64 | fi 65 | else 66 | # macOS 67 | echo "please use homebrew to manually install softwares on macOS" 68 | fi 69 | 70 | # language-pack-zh-hans is only aviailable in ubuntu 71 | if [[ "$distro" = "Ubuntu" ]]; then 72 | header "Installing language-pack-zh-hans" 73 | # also install language-pack-zh-hans 74 | yes | apt install language-pack-zh-hans && echo "success" 75 | fi 76 | 77 | # add zsh to /etc/shells if it's not there 78 | if ! grep -q zsh /etc/shells; then 79 | command -v zsh >> /etc/shells 80 | fi 81 | 82 | # change login shell to zsh 83 | header "Changing Login Shell to zsh" 84 | if chsh -s "$(command -v zsh)"; then 85 | echo "success" 86 | else 87 | err "failed to change login shell to zsh" 88 | exit 3 89 | fi 90 | 91 | if ! diff /usr/share/zoneinfo/Asia/Shanghai /etc/localtime; then 92 | header "Setting Timezone to Asia/Shanghai" 93 | cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "success" 94 | fi 95 | 96 | header "Installing vim-plug" 97 | curl -sfLo ~/.vim/autoload/plug.vim --create-dirs 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' && echo "success" 98 | 99 | header "Installing zsh-syntax-highlighting" 100 | rm -rf ~/zsh-syntax-highlighting \ 101 | && git clone --quiet 'https://github.com/zsh-users/zsh-syntax-highlighting.git' ~/zsh-syntax-highlighting \ 102 | && echo "success" 103 | 104 | header "Configuring .vimrc, .gitconfig & .zshrc" 105 | curl -sL "$repoAddr"/.vimrc > ~/.vimrc 106 | curl -sL "$repoAddr"/.zshrc > ~/.zshrc 107 | curl -sL "$repoAddr"/.gitconfig > ~/.gitconfig 108 | echo "success" 109 | 110 | if [[ "$distro" != "macOS" ]]; then 111 | if [[ -f /etc/ssh/sshd_config ]]; then 112 | header 'File /etc/ssh/sshd_config exits, chaning sshd port from 22 to 9000' 113 | # change sshd port to 9000, set ClientAliveInterval to 5 seconds 114 | # different ISO providers may have different sshd_config, so this may not work 115 | sed -i 's/#Port 22/Port 9000/g' /etc/ssh/sshd_config 116 | sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 5/g' /etc/ssh/sshd_config 117 | service sshd restart 118 | echo 'success' 119 | fi 120 | fi 121 | 122 | echo 123 | echo "System init successful, please run: source ~/.zshrc" 124 | -------------------------------------------------------------------------------- /neo_fetch_config.conf: -------------------------------------------------------------------------------- 1 | # See this wiki page for more info: 2 | # https://github.com/dylanaraps/neofetch/wiki/Customizing-Info 3 | print_info() { 4 | info title 5 | info underline 6 | 7 | info "OS" distro 8 | # info "Host" model 9 | info "Kernel" kernel 10 | info "Uptime" uptime 11 | # info "Packages" packages 12 | info "Shell" shell 13 | # info "Resolution" resolution 14 | info "DE" de 15 | # info "WM" wm 16 | # info "WM Theme" wm_theme 17 | # info "Theme" theme 18 | # info "Icons" icons 19 | # info "Terminal" term 20 | # info "Terminal Font" term_font 21 | info "CPU" cpu 22 | # info "GPU" gpu 23 | info "Memory" memory 24 | 25 | # info "GPU Driver" gpu_driver # Linux/macOS only 26 | # info "CPU Usage" cpu_usage 27 | info "Disk" disk 28 | # info "Battery" battery 29 | # info "Font" font 30 | # info "Song" song 31 | # [[ "$player" ]] && prin "Music Player" "$player" 32 | # info "Local IP" local_ip 33 | info "Public IP" public_ip 34 | # info "Users" users 35 | # info "Locale" locale # This only works on glibc systems. 36 | 37 | info cols 38 | } 39 | 40 | # Title 41 | 42 | 43 | # Hide/Show Fully qualified domain name. 44 | # 45 | # Default: 'off' 46 | # Values: 'on', 'off' 47 | # Flag: --title_fqdn 48 | title_fqdn="off" 49 | 50 | 51 | # Kernel 52 | 53 | 54 | # Shorten the output of the kernel function. 55 | # 56 | # Default: 'on' 57 | # Values: 'on', 'off' 58 | # Flag: --kernel_shorthand 59 | # Supports: Everything except *BSDs (except PacBSD and PC-BSD) 60 | # 61 | # Example: 62 | # on: '4.8.9-1-ARCH' 63 | # off: 'Linux 4.8.9-1-ARCH' 64 | kernel_shorthand="off" 65 | 66 | 67 | # Distro 68 | 69 | 70 | # Shorten the output of the distro function 71 | # 72 | # Default: 'off' 73 | # Values: 'on', 'tiny', 'off' 74 | # Flag: --distro_shorthand 75 | # Supports: Everything except Windows and Haiku 76 | distro_shorthand="off" 77 | 78 | # Show/Hide OS Architecture. 79 | # Show 'x86_64', 'x86' and etc in 'Distro:' output. 80 | # 81 | # Default: 'on' 82 | # Values: 'on', 'off' 83 | # Flag: --os_arch 84 | # 85 | # Example: 86 | # on: 'Arch Linux x86_64' 87 | # off: 'Arch Linux' 88 | os_arch="on" 89 | 90 | 91 | # Uptime 92 | 93 | 94 | # Shorten the output of the uptime function 95 | # 96 | # Default: 'on' 97 | # Values: 'on', 'tiny', 'off' 98 | # Flag: --uptime_shorthand 99 | # 100 | # Example: 101 | # on: '2 days, 10 hours, 3 mins' 102 | # tiny: '2d 10h 3m' 103 | # off: '2 days, 10 hours, 3 minutes' 104 | uptime_shorthand="tiny" 105 | 106 | 107 | # Memory 108 | 109 | 110 | # Show memory pecentage in output. 111 | # 112 | # Default: 'off' 113 | # Values: 'on', 'off' 114 | # Flag: --memory_percent 115 | # 116 | # Example: 117 | # on: '1801MiB / 7881MiB (22%)' 118 | # off: '1801MiB / 7881MiB' 119 | memory_percent="on" 120 | 121 | # Change memory output unit. 122 | # 123 | # Default: 'mib' 124 | # Values: 'kib', 'mib', 'gib' 125 | # Flag: --memory_unit 126 | # 127 | # Example: 128 | # kib '1020928KiB / 7117824KiB' 129 | # mib '1042MiB / 6951MiB' 130 | # gib: ' 0.98GiB / 6.79GiB' 131 | memory_unit="mib" 132 | 133 | 134 | # Packages 135 | 136 | 137 | # Show/Hide Package Manager names. 138 | # 139 | # Default: 'tiny' 140 | # Values: 'on', 'tiny' 'off' 141 | # Flag: --package_managers 142 | # 143 | # Example: 144 | # on: '998 (pacman), 8 (flatpak), 4 (snap)' 145 | # tiny: '908 (pacman, flatpak, snap)' 146 | # off: '908' 147 | package_managers="on" 148 | 149 | 150 | # Shell 151 | 152 | 153 | # Show the path to $SHELL 154 | # 155 | # Default: 'off' 156 | # Values: 'on', 'off' 157 | # Flag: --shell_path 158 | # 159 | # Example: 160 | # on: '/bin/bash' 161 | # off: 'bash' 162 | shell_path="off" 163 | 164 | # Show $SHELL version 165 | # 166 | # Default: 'on' 167 | # Values: 'on', 'off' 168 | # Flag: --shell_version 169 | # 170 | # Example: 171 | # on: 'bash 4.4.5' 172 | # off: 'bash' 173 | shell_version="on" 174 | 175 | 176 | # CPU 177 | 178 | 179 | # CPU speed type 180 | # 181 | # Default: 'bios_limit' 182 | # Values: 'scaling_cur_freq', 'scaling_min_freq', 'scaling_max_freq', 'bios_limit'. 183 | # Flag: --speed_type 184 | # Supports: Linux with 'cpufreq' 185 | # NOTE: Any file in '/sys/devices/system/cpu/cpu0/cpufreq' can be used as a value. 186 | speed_type="bios_limit" 187 | 188 | # CPU speed shorthand 189 | # 190 | # Default: 'off' 191 | # Values: 'on', 'off'. 192 | # Flag: --speed_shorthand 193 | # NOTE: This flag is not supported in systems with CPU speed less than 1 GHz 194 | # 195 | # Example: 196 | # on: 'i7-6500U (4) @ 3.1GHz' 197 | # off: 'i7-6500U (4) @ 3.100GHz' 198 | speed_shorthand="on" 199 | 200 | # Enable/Disable CPU brand in output. 201 | # 202 | # Default: 'on' 203 | # Values: 'on', 'off' 204 | # Flag: --cpu_brand 205 | # 206 | # Example: 207 | # on: 'Intel i7-6500U' 208 | # off: 'i7-6500U (4)' 209 | cpu_brand="on" 210 | 211 | # CPU Speed 212 | # Hide/Show CPU speed. 213 | # 214 | # Default: 'on' 215 | # Values: 'on', 'off' 216 | # Flag: --cpu_speed 217 | # 218 | # Example: 219 | # on: 'Intel i7-6500U (4) @ 3.1GHz' 220 | # off: 'Intel i7-6500U (4)' 221 | cpu_speed="on" 222 | 223 | # CPU Cores 224 | # Display CPU cores in output 225 | # 226 | # Default: 'logical' 227 | # Values: 'logical', 'physical', 'off' 228 | # Flag: --cpu_cores 229 | # Support: 'physical' doesn't work on BSD. 230 | # 231 | # Example: 232 | # logical: 'Intel i7-6500U (4) @ 3.1GHz' (All virtual cores) 233 | # physical: 'Intel i7-6500U (2) @ 3.1GHz' (All physical cores) 234 | # off: 'Intel i7-6500U @ 3.1GHz' 235 | cpu_cores="logical" 236 | 237 | # CPU Temperature 238 | # Hide/Show CPU temperature. 239 | # Note the temperature is added to the regular CPU function. 240 | # 241 | # Default: 'off' 242 | # Values: 'C', 'F', 'off' 243 | # Flag: --cpu_temp 244 | # Supports: Linux, BSD 245 | # NOTE: For FreeBSD and NetBSD-based systems, you'll need to enable 246 | # coretemp kernel module. This only supports newer Intel processors. 247 | # 248 | # Example: 249 | # C: 'Intel i7-6500U (4) @ 3.1GHz [27.2°C]' 250 | # F: 'Intel i7-6500U (4) @ 3.1GHz [82.0°F]' 251 | # off: 'Intel i7-6500U (4) @ 3.1GHz' 252 | cpu_temp="on" 253 | 254 | 255 | # GPU 256 | 257 | 258 | # Enable/Disable GPU Brand 259 | # 260 | # Default: 'on' 261 | # Values: 'on', 'off' 262 | # Flag: --gpu_brand 263 | # 264 | # Example: 265 | # on: 'AMD HD 7950' 266 | # off: 'HD 7950' 267 | gpu_brand="off" 268 | 269 | # Which GPU to display 270 | # 271 | # Default: 'all' 272 | # Values: 'all', 'dedicated', 'integrated' 273 | # Flag: --gpu_type 274 | # Supports: Linux 275 | # 276 | # Example: 277 | # all: 278 | # GPU1: AMD HD 7950 279 | # GPU2: Intel Integrated Graphics 280 | # 281 | # dedicated: 282 | # GPU1: AMD HD 7950 283 | # 284 | # integrated: 285 | # GPU1: Intel Integrated Graphics 286 | gpu_type="all" 287 | 288 | 289 | # Resolution 290 | 291 | 292 | # Display refresh rate next to each monitor 293 | # Default: 'off' 294 | # Values: 'on', 'off' 295 | # Flag: --refresh_rate 296 | # Supports: Doesn't work on Windows. 297 | # 298 | # Example: 299 | # on: '1920x1080 @ 60Hz' 300 | # off: '1920x1080' 301 | refresh_rate="off" 302 | 303 | 304 | # Gtk Theme / Icons / Font 305 | 306 | 307 | # Shorten output of GTK Theme / Icons / Font 308 | # 309 | # Default: 'off' 310 | # Values: 'on', 'off' 311 | # Flag: --gtk_shorthand 312 | # 313 | # Example: 314 | # on: 'Numix, Adwaita' 315 | # off: 'Numix [GTK2], Adwaita [GTK3]' 316 | gtk_shorthand="off" 317 | 318 | 319 | # Enable/Disable gtk2 Theme / Icons / Font 320 | # 321 | # Default: 'on' 322 | # Values: 'on', 'off' 323 | # Flag: --gtk2 324 | # 325 | # Example: 326 | # on: 'Numix [GTK2], Adwaita [GTK3]' 327 | # off: 'Adwaita [GTK3]' 328 | gtk2="on" 329 | 330 | # Enable/Disable gtk3 Theme / Icons / Font 331 | # 332 | # Default: 'on' 333 | # Values: 'on', 'off' 334 | # Flag: --gtk3 335 | # 336 | # Example: 337 | # on: 'Numix [GTK2], Adwaita [GTK3]' 338 | # off: 'Numix [GTK2]' 339 | gtk3="on" 340 | 341 | 342 | # IP Address 343 | 344 | 345 | # Website to ping for the public IP 346 | # 347 | # Default: 'http://ident.me' 348 | # Values: 'url' 349 | # Flag: --ip_host 350 | public_ip_host="http://ident.me" 351 | 352 | # Public IP timeout. 353 | # 354 | # Default: '2' 355 | # Values: 'int' 356 | # Flag: --ip_timeout 357 | public_ip_timeout=3 358 | 359 | 360 | # Desktop Environment 361 | 362 | 363 | # Show Desktop Environment version 364 | # 365 | # Default: 'on' 366 | # Values: 'on', 'off' 367 | # Flag: --de_version 368 | de_version="on" 369 | 370 | 371 | # Disk 372 | 373 | 374 | # Which disks to display. 375 | # The values can be any /dev/sdXX, mount point or directory. 376 | # NOTE: By default we only show the disk info for '/'. 377 | # 378 | # Default: '/' 379 | # Values: '/', '/dev/sdXX', '/path/to/drive'. 380 | # Flag: --disk_show 381 | # 382 | # Example: 383 | # disk_show=('/' '/dev/sdb1'): 384 | # 'Disk (/): 74G / 118G (66%)' 385 | # 'Disk (/mnt/Videos): 823G / 893G (93%)' 386 | # 387 | # disk_show=('/'): 388 | # 'Disk (/): 74G / 118G (66%)' 389 | # 390 | disk_show=('/') 391 | 392 | # Disk subtitle. 393 | # What to append to the Disk subtitle. 394 | # 395 | # Default: 'mount' 396 | # Values: 'mount', 'name', 'dir', 'none' 397 | # Flag: --disk_subtitle 398 | # 399 | # Example: 400 | # name: 'Disk (/dev/sda1): 74G / 118G (66%)' 401 | # 'Disk (/dev/sdb2): 74G / 118G (66%)' 402 | # 403 | # mount: 'Disk (/): 74G / 118G (66%)' 404 | # 'Disk (/mnt/Local Disk): 74G / 118G (66%)' 405 | # 'Disk (/mnt/Videos): 74G / 118G (66%)' 406 | # 407 | # dir: 'Disk (/): 74G / 118G (66%)' 408 | # 'Disk (Local Disk): 74G / 118G (66%)' 409 | # 'Disk (Videos): 74G / 118G (66%)' 410 | # 411 | # none: 'Disk: 74G / 118G (66%)' 412 | # 'Disk: 74G / 118G (66%)' 413 | # 'Disk: 74G / 118G (66%)' 414 | disk_subtitle="mount" 415 | 416 | # Disk percent. 417 | # Show/Hide disk percent. 418 | # 419 | # Default: 'on' 420 | # Values: 'on', 'off' 421 | # Flag: --disk_percent 422 | # 423 | # Example: 424 | # on: 'Disk (/): 74G / 118G (66%)' 425 | # off: 'Disk (/): 74G / 118G' 426 | disk_percent="on" 427 | 428 | 429 | # Song 430 | 431 | 432 | # Manually specify a music player. 433 | # 434 | # Default: 'auto' 435 | # Values: 'auto', 'player-name' 436 | # Flag: --music_player 437 | # 438 | # Available values for 'player-name': 439 | # 440 | # amarok 441 | # audacious 442 | # banshee 443 | # bluemindo 444 | # clementine 445 | # cmus 446 | # deadbeef 447 | # deepin-music 448 | # dragon 449 | # elisa 450 | # exaile 451 | # gnome-music 452 | # gmusicbrowser 453 | # gogglesmm 454 | # guayadeque 455 | # io.elementary.music 456 | # iTunes 457 | # juk 458 | # lollypop 459 | # mocp 460 | # mopidy 461 | # mpd 462 | # muine 463 | # netease-cloud-music 464 | # olivia 465 | # playerctl 466 | # pogo 467 | # pragha 468 | # qmmp 469 | # quodlibet 470 | # rhythmbox 471 | # sayonara 472 | # smplayer 473 | # spotify 474 | # strawberry 475 | # tauonmb 476 | # tomahawk 477 | # vlc 478 | # xmms2d 479 | # xnoise 480 | # yarock 481 | music_player="auto" 482 | 483 | # Format to display song information. 484 | # 485 | # Default: '%artist% - %album% - %title%' 486 | # Values: '%artist%', '%album%', '%title%' 487 | # Flag: --song_format 488 | # 489 | # Example: 490 | # default: 'Song: Jet - Get Born - Sgt Major' 491 | song_format="%artist% - %album% - %title%" 492 | 493 | # Print the Artist, Album and Title on separate lines 494 | # 495 | # Default: 'off' 496 | # Values: 'on', 'off' 497 | # Flag: --song_shorthand 498 | # 499 | # Example: 500 | # on: 'Artist: The Fratellis' 501 | # 'Album: Costello Music' 502 | # 'Song: Chelsea Dagger' 503 | # 504 | # off: 'Song: The Fratellis - Costello Music - Chelsea Dagger' 505 | song_shorthand="off" 506 | 507 | # 'mpc' arguments (specify a host, password etc). 508 | # 509 | # Default: '' 510 | # Example: mpc_args=(-h HOST -P PASSWORD) 511 | mpc_args=() 512 | 513 | 514 | # Text Colors 515 | 516 | 517 | # Text Colors 518 | # 519 | # Default: 'distro' 520 | # Values: 'distro', 'num' 'num' 'num' 'num' 'num' 'num' 521 | # Flag: --colors 522 | # 523 | # Each number represents a different part of the text in 524 | # this order: 'title', '@', 'underline', 'subtitle', 'colon', 'info' 525 | # 526 | # Example: 527 | # colors=(distro) - Text is colored based on Distro colors. 528 | # colors=(4 6 1 8 8 6) - Text is colored in the order above. 529 | colors=(distro) 530 | 531 | 532 | # Text Options 533 | 534 | 535 | # Toggle bold text 536 | # 537 | # Default: 'on' 538 | # Values: 'on', 'off' 539 | # Flag: --bold 540 | bold="on" 541 | 542 | # Enable/Disable Underline 543 | # 544 | # Default: 'on' 545 | # Values: 'on', 'off' 546 | # Flag: --underline 547 | underline_enabled="on" 548 | 549 | # Underline character 550 | # 551 | # Default: '-' 552 | # Values: 'string' 553 | # Flag: --underline_char 554 | underline_char="-" 555 | 556 | 557 | # Info Separator 558 | # Replace the default separator with the specified string. 559 | # 560 | # Default: ':' 561 | # Flag: --separator 562 | # 563 | # Example: 564 | # separator="->": 'Shell-> bash' 565 | # separator=" =": 'WM = dwm' 566 | separator=":" 567 | 568 | 569 | # Color Blocks 570 | 571 | 572 | # Color block range 573 | # The range of colors to print. 574 | # 575 | # Default: '0', '15' 576 | # Values: 'num' 577 | # Flag: --block_range 578 | # 579 | # Example: 580 | # 581 | # Display colors 0-7 in the blocks. (8 colors) 582 | # neofetch --block_range 0 7 583 | # 584 | # Display colors 0-15 in the blocks. (16 colors) 585 | # neofetch --block_range 0 15 586 | block_range=(0 15) 587 | 588 | # Toggle color blocks 589 | # 590 | # Default: 'on' 591 | # Values: 'on', 'off' 592 | # Flag: --color_blocks 593 | color_blocks="on" 594 | 595 | # Color block width in spaces 596 | # 597 | # Default: '3' 598 | # Values: 'num' 599 | # Flag: --block_width 600 | block_width=3 601 | 602 | # Color block height in lines 603 | # 604 | # Default: '1' 605 | # Values: 'num' 606 | # Flag: --block_height 607 | block_height=1 608 | 609 | # Color Alignment 610 | # 611 | # Default: 'auto' 612 | # Values: 'auto', 'num' 613 | # Flag: --col_offset 614 | # 615 | # Number specifies how far from the left side of the terminal (in spaces) to 616 | # begin printing the columns, in case you want to e.g. center them under your 617 | # text. 618 | # Example: 619 | # col_offset="auto" - Default behavior of neofetch 620 | # col_offset=7 - Leave 7 spaces then print the colors 621 | col_offset="auto" 622 | 623 | # Progress Bars 624 | 625 | 626 | # Bar characters 627 | # 628 | # Default: '-', '=' 629 | # Values: 'string', 'string' 630 | # Flag: --bar_char 631 | # 632 | # Example: 633 | # neofetch --bar_char 'elapsed' 'total' 634 | # neofetch --bar_char '-' '=' 635 | bar_char_elapsed="-" 636 | bar_char_total="=" 637 | 638 | # Toggle Bar border 639 | # 640 | # Default: 'on' 641 | # Values: 'on', 'off' 642 | # Flag: --bar_border 643 | bar_border="on" 644 | 645 | # Progress bar length in spaces 646 | # Number of chars long to make the progress bars. 647 | # 648 | # Default: '15' 649 | # Values: 'num' 650 | # Flag: --bar_length 651 | bar_length=15 652 | 653 | # Progress bar colors 654 | # When set to distro, uses your distro's logo colors. 655 | # 656 | # Default: 'distro', 'distro' 657 | # Values: 'distro', 'num' 658 | # Flag: --bar_colors 659 | # 660 | # Example: 661 | # neofetch --bar_colors 3 4 662 | # neofetch --bar_colors distro 5 663 | bar_color_elapsed="distro" 664 | bar_color_total="distro" 665 | 666 | 667 | # Info display 668 | # Display a bar with the info. 669 | # 670 | # Default: 'off' 671 | # Values: 'bar', 'infobar', 'barinfo', 'off' 672 | # Flags: --cpu_display 673 | # --memory_display 674 | # --battery_display 675 | # --disk_display 676 | # 677 | # Example: 678 | # bar: '[---=======]' 679 | # infobar: 'info [---=======]' 680 | # barinfo: '[---=======] info' 681 | # off: 'info' 682 | cpu_display="off" 683 | memory_display="off" 684 | battery_display="off" 685 | disk_display="off" 686 | 687 | 688 | # Backend Settings 689 | 690 | 691 | # Image backend. 692 | # 693 | # Default: 'ascii' 694 | # Values: 'ascii', 'caca', 'chafa', 'jp2a', 'iterm2', 'off', 695 | # 'pot', 'termpix', 'pixterm', 'tycat', 'w3m', 'kitty' 696 | # Flag: --backend 697 | image_backend="ascii" 698 | 699 | # Image Source 700 | # 701 | # Which image or ascii file to display. 702 | # 703 | # Default: 'auto' 704 | # Values: 'auto', 'ascii', 'wallpaper', '/path/to/img', '/path/to/ascii', '/path/to/dir/' 705 | # 'command output (neofetch --ascii "$(fortune | cowsay -W 30)")' 706 | # Flag: --source 707 | # 708 | # NOTE: 'auto' will pick the best image source for whatever image backend is used. 709 | # In ascii mode, distro ascii art will be used and in an image mode, your 710 | # wallpaper will be used. 711 | image_source="auto" 712 | 713 | 714 | # Ascii Options 715 | 716 | 717 | # Ascii distro 718 | # Which distro's ascii art to display. 719 | # 720 | # Default: 'auto' 721 | # Values: 'auto', 'distro_name' 722 | # Flag: --ascii_distro 723 | # NOTE: AIX, Alpine, Anarchy, Android, Antergos, antiX, "AOSC OS", 724 | # "AOSC OS/Retro", Apricity, ArcoLinux, ArchBox, ARCHlabs, 725 | # ArchStrike, XFerience, ArchMerge, Arch, Artix, Arya, Bedrock, 726 | # Bitrig, BlackArch, BLAG, BlankOn, BlueLight, bonsai, BSD, 727 | # BunsenLabs, Calculate, Carbs, CentOS, Chakra, ChaletOS, 728 | # Chapeau, Chrom*, Cleanjaro, ClearOS, Clear_Linux, Clover, 729 | # Condres, Container_Linux, CRUX, Cucumber, Debian, Deepin, 730 | # DesaOS, Devuan, DracOS, DarkOs, DragonFly, Drauger, Elementary, 731 | # EndeavourOS, Endless, EuroLinux, Exherbo, Fedora, Feren, FreeBSD, 732 | # FreeMiNT, Frugalware, Funtoo, GalliumOS, Garuda, Gentoo, Pentoo, 733 | # gNewSense, GNOME, GNU, GoboLinux, Grombyang, Guix, Haiku, Huayra, 734 | # Hyperbola, janus, Kali, KaOS, KDE_neon, Kibojoe, Kogaion, 735 | # Korora, KSLinux, Kubuntu, LEDE, LFS, Linux_Lite, 736 | # LMDE, Lubuntu, Lunar, macos, Mageia, MagpieOS, Mandriva, 737 | # Manjaro, Maui, Mer, Minix, LinuxMint, MX_Linux, Namib, 738 | # Neptune, NetBSD, Netrunner, Nitrux, NixOS, Nurunner, 739 | # NuTyX, OBRevenge, OpenBSD, openEuler, OpenIndiana, openmamba, 740 | # OpenMandriva, OpenStage, OpenWrt, osmc, Oracle, OS Elbrus, PacBSD, 741 | # Parabola, Pardus, Parrot, Parsix, TrueOS, PCLinuxOS, Peppermint, 742 | # popos, Porteus, PostMarketOS, Proxmox, Puppy, PureOS, Qubes, Radix, 743 | # Raspbian, Reborn_OS, Redstar, Redcore, Redhat, Refracted_Devuan, 744 | # Regata, Rosa, sabotage, Sabayon, Sailfish, SalentOS, Scientific, 745 | # Septor, SereneLinux, SharkLinux, Siduction, Slackware, SliTaz, 746 | # SmartOS, Solus, Source_Mage, Sparky, Star, SteamOS, SunOS, 747 | # openSUSE_Leap, openSUSE_Tumbleweed, openSUSE, SwagArch, Tails, 748 | # Trisquel, Ubuntu-Budgie, Ubuntu-GNOME, Ubuntu-MATE, Ubuntu-Studio, 749 | # Ubuntu, Venom, Void, Obarun, windows10, Windows7, Xubuntu, Zorin, 750 | # and IRIX have ascii logos 751 | # NOTE: Arch, Ubuntu, Redhat, and Dragonfly have 'old' logo variants. 752 | # Use '{distro name}_old' to use the old logos. 753 | # NOTE: Ubuntu has flavor variants. 754 | # Change this to Lubuntu, Kubuntu, Xubuntu, Ubuntu-GNOME, 755 | # Ubuntu-Studio, Ubuntu-Mate or Ubuntu-Budgie to use the flavors. 756 | # NOTE: Arcolinux, Dragonfly, Fedora, Alpine, Arch, Ubuntu, 757 | # CRUX, Debian, Gentoo, FreeBSD, Mac, NixOS, OpenBSD, android, 758 | # Antrix, CentOS, Cleanjaro, ElementaryOS, GUIX, Hyperbola, 759 | # Manjaro, MXLinux, NetBSD, Parabola, POP_OS, PureOS, 760 | # Slackware, SunOS, LinuxLite, OpenSUSE, Raspbian, 761 | # postmarketOS, and Void have a smaller logo variant. 762 | # Use '{distro name}_small' to use the small variants. 763 | ascii_distro="bsd" 764 | 765 | # Ascii Colors 766 | # 767 | # Default: 'distro' 768 | # Values: 'distro', 'num' 'num' 'num' 'num' 'num' 'num' 769 | # Flag: --ascii_colors 770 | # 771 | # Example: 772 | # ascii_colors=(distro) - Ascii is colored based on Distro colors. 773 | # ascii_colors=(4 6 1 8 8 6) - Ascii is colored using these colors. 774 | ascii_colors=(distro) 775 | 776 | # Bold ascii logo 777 | # Whether or not to bold the ascii logo. 778 | # 779 | # Default: 'on' 780 | # Values: 'on', 'off' 781 | # Flag: --ascii_bold 782 | ascii_bold="on" 783 | 784 | 785 | # Image Options 786 | 787 | 788 | # Image loop 789 | # Setting this to on will make neofetch redraw the image constantly until 790 | # Ctrl+C is pressed. This fixes display issues in some terminal emulators. 791 | # 792 | # Default: 'off' 793 | # Values: 'on', 'off' 794 | # Flag: --loop 795 | image_loop="off" 796 | 797 | # Thumbnail directory 798 | # 799 | # Default: '~/.cache/thumbnails/neofetch' 800 | # Values: 'dir' 801 | thumbnail_dir="${XDG_CACHE_HOME:-${HOME}/.cache}/thumbnails/neofetch" 802 | 803 | # Crop mode 804 | # 805 | # Default: 'normal' 806 | # Values: 'normal', 'fit', 'fill' 807 | # Flag: --crop_mode 808 | # 809 | # See this wiki page to learn about the fit and fill options. 810 | # https://github.com/dylanaraps/neofetch/wiki/What-is-Waifu-Crop%3F 811 | crop_mode="normal" 812 | 813 | # Crop offset 814 | # Note: Only affects 'normal' crop mode. 815 | # 816 | # Default: 'center' 817 | # Values: 'northwest', 'north', 'northeast', 'west', 'center' 818 | # 'east', 'southwest', 'south', 'southeast' 819 | # Flag: --crop_offset 820 | crop_offset="center" 821 | 822 | # Image size 823 | # The image is half the terminal width by default. 824 | # 825 | # Default: 'auto' 826 | # Values: 'auto', '00px', '00%', 'none' 827 | # Flags: --image_size 828 | # --size 829 | image_size="auto" 830 | 831 | # Gap between image and text 832 | # 833 | # Default: '3' 834 | # Values: 'num', '-num' 835 | # Flag: --gap 836 | gap=3 837 | 838 | # Image offsets 839 | # Only works with the w3m backend. 840 | # 841 | # Default: '0' 842 | # Values: 'px' 843 | # Flags: --xoffset 844 | # --yoffset 845 | yoffset=0 846 | xoffset=0 847 | 848 | # Image background color 849 | # Only works with the w3m backend. 850 | # 851 | # Default: '' 852 | # Values: 'color', 'blue' 853 | # Flag: --bg_color 854 | background_color= 855 | 856 | 857 | # Misc Options 858 | 859 | # Stdout mode 860 | # Turn off all colors and disables image backend (ASCII/Image). 861 | # Useful for piping into another command. 862 | # Default: 'off' 863 | # Values: 'on', 'off' 864 | stdout="off" 865 | -------------------------------------------------------------------------------- /tools/3p.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 3p: program, port, pid 4 | # aim: coross reference 3p 5 | 6 | # example usage: 7 | # bash <(curl -sL http://realrz.com/shell-scripts/tools/3p.sh) --program nginx 8 | # bash <(curl -sL http://realrz.com/shell-scripts/tools/3p.sh) --port 80 9 | # bash <(curl -sL http://realrz.com/shell-scripts/tools/3p.sh) --pid 1234 10 | 11 | # output format example(each line except the header represents a single process): 12 | # Program Pid Port 13 | # nginx 87236 80,443 14 | # nginx 358789 none 15 | 16 | # util functions 17 | 18 | function err() { 19 | echo "$1" >&2 20 | } 21 | 22 | function getDistro() { 23 | local distro 24 | if [[ -e /etc/os-release ]]; then 25 | # Linux has /etc/os-release file 26 | # shellcheck disable=SC1091 27 | source /etc/os-release 28 | # /etc/os-release when sourced, will add the $NAME environment variable 29 | if echo "$NAME" | grep -iq ubuntu; then 30 | distro="Ubuntu" 31 | fi 32 | elif [[ $(uname) == "Darwin" ]]; then 33 | distro="macOS" 34 | else 35 | echo "Sorry, this script only support Ubuntu & macOS" 36 | exit 1 37 | fi 38 | echo "$distro" 39 | } 40 | 41 | # check distro 42 | 43 | if ! distro=$(getDistro); then 44 | exit 1 45 | fi 46 | 47 | if [[ "$distro" != "Ubuntu" ]]; then 48 | echo "Sorry, this script only supports Ubuntu" 49 | exit 2 50 | fi 51 | 52 | # check if awk & netstat is installed, if not, install them 53 | if ! (command -v awk netstat &> /dev/null); then 54 | apt update 55 | yes | apt install awk net-tools &> /dev/null 56 | fi 57 | 58 | # find port(s) by pid, 1 process can listen on many ports 59 | function printPortsByPid { 60 | ports=$( 61 | netstat -tulpn \ 62 | | awk -v pattern="^$1" '(NR>2 && $7 ~ pattern){print $4}' \ 63 | | awk -F':' '{print $NF}' \ 64 | | sort -n \ 65 | | uniq \ 66 | | tr '\n' ',' \ 67 | | sed 's/,$//' 68 | ) 69 | echo "$ports" 70 | } 71 | 72 | # format output 73 | function printResultHeader { 74 | printf "%-15s %-10s %-20s\n" "Program" "Pid" "Port" 75 | } 76 | function printResultBody { 77 | local program="$1" 78 | local pid="$2" 79 | local port="$3" 80 | if [[ -z "$port" ]]; then 81 | port="none" 82 | fi 83 | printf "%-15s %-10d %-20s\n" "$program" "$pid" "$port" 84 | } 85 | 86 | # main program starts here 87 | if [[ "$#" -ne 2 ]]; then 88 | err "wrong usage" 89 | exit 3; 90 | elif [[ "$1" = "--port" ]]; then 91 | port="$2" 92 | segment=$(netstat -tulpn | awk -v pattern=":$port$" '(NR>2 && $4 ~ pattern){print $7}') 93 | if [[ -z "$segment" ]]; then 94 | err "no process is listening on port $port" 95 | exit 4 96 | fi 97 | # if port is valid, there must be 1 and only 1 process and program listening to it 98 | # find program 99 | program=$(echo "$segment" | awk -F'[/:]' '{print $2}' | sort | uniq) 100 | # find pid 101 | pid=$(echo "$segment" | awk -F'[/:]' '{print $1}' | sort | uniq) 102 | # format & output 103 | printResultHeader 104 | printResultBody "$program" "$pid" "$port" 105 | elif [[ "$1" = "--pid" ]]; then 106 | pid="$2" 107 | # find program 108 | program=$( 109 | ps aux \ 110 | | awk -v pid="$pid" '($2==pid){print $11}' \ 111 | | cut -d':' -f1 \ 112 | | awk -F'/' '{print $NF}' 113 | ) 114 | if [[ -z "$program" ]]; then 115 | err "no running process has pid $pid" 116 | exit 5 117 | fi 118 | # find port(s), 1 process can listen on many ports 119 | port=$(printPortsByPid "$pid") 120 | # format & output 121 | printResultHeader 122 | printResultBody "$program" "$pid" "$port" 123 | elif [[ "$1" = "--program" ]]; then 124 | program="$2" 125 | # test if program exits 126 | if ! (command -v "$program" &>/dev/null); then 127 | err "$program doesn't exist" 128 | exit 6 129 | fi 130 | # find pid(s), a program can have many process 131 | # pgrep -x flag means exact match 132 | pid=$(pgrep -x "$program") 133 | if [[ -z "$pid" ]]; then 134 | err "$program doesn't have any running process" 135 | exit 7 136 | fi 137 | printResultHeader 138 | # for each pid, find port 139 | while read -r line 140 | do 141 | port=$(printPortsByPid "$line") 142 | printResultBody "$program" "$line" "$port" 143 | done <<< "$pid" 144 | else 145 | err "wrong option" 146 | exit 8; 147 | fi 148 | -------------------------------------------------------------------------------- /tools/gsync.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # gsync: git sync 4 | # aim: bidirectional sync between local and remote git repo 5 | 6 | # usage: 7 | # 1. sync current branch: bash gsync.sh 8 | # 2. sync specific branch: bash gsync.sh {branch name} 9 | # e.g. bash gsync.sh dev 10 | 11 | # note: this script will peform auto merge when local & remote branch are diverged 12 | # rebase is not supported yet, maybe I'll add it later 13 | 14 | if ! branch=$(git branch --show-current); then 15 | # one of the reason you may come to this is: 16 | # current folder is not even monitored by git 17 | exit 1 18 | fi 19 | 20 | # if parameter is provided 21 | if [[ -n "$1" ]]; then 22 | if [[ ! $(git branch --list) =~ $1 ]]; then 23 | echo "branch $1 doesn't exist" 24 | exit 2 25 | fi 26 | if [[ "$branch" != "$1" ]]; then 27 | branch="$1" 28 | git switch "$1" 29 | fi 30 | fi 31 | 32 | # fetch new changes in remote repo 33 | if ! git fetch; then 34 | # you may come to this if you network went wrong 35 | # e.g. GFW can act like a bitch sometimes 36 | exit 3 37 | fi 38 | 39 | status=$(git status) 40 | 41 | if [[ "$status" =~ ahead ]]; then 42 | echo "** Pushing local changes to origin/$branch **" 43 | if ! git push; then 44 | exit 4 45 | fi 46 | elif [[ "$status" =~ behind ]]; then 47 | echo "** Pulling remote changes from origin/$branch **" 48 | if ! git merge origin/"$branch" --ff-only; then 49 | exit 5 50 | fi 51 | elif [[ "$status" =~ diverged ]]; then 52 | # try to perform auto merge 53 | if git merge origin/"$branch" --no-edit; then 54 | echo "** Pushing changes to origin/$branch after successful merge **" 55 | if ! git push; then 56 | exit 4 57 | fi 58 | else 59 | echo "There seems to be merge conflicts, please resolve them mannually" 60 | exit 6 61 | fi 62 | elif [[ "$status" =~ 'up to date' ]]; then 63 | echo "You branch is already up to date with origin/$branch" 64 | else 65 | echo "An unknown error occured, check the script you are running" 66 | exit 7 67 | fi 68 | -------------------------------------------------------------------------------- /tools/snp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # snp => show non-printable 4 | # aim: explicitly show common non-printable characters in their escaped form 5 | # distro support: Ubuntu, macOS 6 | # usage: bash <(curl -sL http://realrz.com/shell-scripts/tools/snp.sh) /path/to/file 7 | 8 | # supported mappings 9 | # 1. carriage return => \r 10 | # 2. newline (line feed) => \n 11 | # 3. tab => \t 12 | # 4. space => \x20 13 | 14 | # options 15 | # by default, all the mappings are included, you can specify those mappings using options: 16 | # -r: carriage return 17 | # -n: newline (line feed) 18 | # -t: tab 19 | # -s: space 20 | # options can be combined, e.g. 21 | # bash <(curl -sL http://realrz.com/shell-scripts/snp.sh) -rn /path/to/file 22 | 23 | # util functions 24 | 25 | function err() { 26 | echo "$1" >&2 27 | } 28 | 29 | function getDistro() { 30 | local distro 31 | if [[ -e /etc/os-release ]]; then 32 | # Linux has /etc/os-release file 33 | # shellcheck disable=SC1091 34 | source /etc/os-release 35 | # /etc/os-release when sourced, will add the $NAME environment variable 36 | if echo "$NAME" | grep -iq ubuntu; then 37 | distro="Ubuntu" 38 | fi 39 | elif [[ $(uname) == "Darwin" ]]; then 40 | distro="macOS" 41 | else 42 | echo "Sorry, this script only support Ubuntu & macOS" 43 | exit 1 44 | fi 45 | echo "$distro" 46 | } 47 | 48 | # check distro 49 | if ! distro=$(getDistro); then 50 | exit 1 51 | fi 52 | 53 | # check if xxd is installed 54 | if ! command -v xxd &>/dev/null; then 55 | if [[ "$distro" == "debian" || "$distro" == "ubuntu" ]]; then 56 | yes | apt install xxd &> /dev/null 57 | else 58 | err "this script requires xxd to run" 59 | err "try install xxd first, then run this script again" 60 | exit 1 61 | fi 62 | fi 63 | 64 | # character UTF-8 hex Printable 65 | # line feed 0a no 66 | # carriage return 0d no 67 | # tab 09 no 68 | # space 20 no 69 | # \ 5c yes 70 | # n 6e yes 71 | # r 72 yes 72 | # t 74 yes 73 | # x 78 yes 74 | # 2 32 yes 75 | # 0 30 yes 76 | 77 | # main program starts here 78 | xxd -c 1 "$1" \ 79 | | awk '{print $2}' \ 80 | | sed 's/0a/5c6e/g' \ 81 | | sed 's/0d/5c72/g' \ 82 | | sed 's/09/5c74/g' \ 83 | | sed 's/20/5c783230/g' \ 84 | | tr -d '\n' \ 85 | | xxd -r -p 86 | # use echo to add newline to the end 87 | echo 88 | -------------------------------------------------------------------------------- /tools/v2ray_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # util functions 4 | 5 | function err() { 6 | echo "$1" >&2 7 | } 8 | 9 | # pre-requisites 10 | 11 | echo "V2ray + tls + nginx + websocket 安装配置脚本" 12 | 13 | echo "在运行此脚本之前,以下条件应该被满足:" 14 | echo "1. 系统是 Ubuntu 或者 Debian 并且使用 root 账号登陆" 15 | echo "2. 系统不在 GFW 封锁范围内" 16 | echo "3. 系统上没有安装过 certbot" 17 | echo "4. 已经准备好域名并且 DNS 的 A 记录已经将域名指向本机的IP地址" 18 | 19 | read -p "是否继续? (Y/N) " -r answer 20 | if [[ $answer != "Y" ]] && [[ $answer != "y" ]]; then 21 | err "已退出" 22 | exit 1 23 | fi 24 | 25 | apt update 26 | 27 | # get domain 28 | read -p "请输入域名: " -r domain 29 | 30 | # install curl, nginx, snapd and certbot 31 | yes | apt install curl nginx snapd 32 | snap install --classic certbot 33 | if [[ ! -f /usr/bin/certbot ]]; then 34 | ln -s /snap/bin/certbot /usr/bin/certbot 35 | fi 36 | 37 | # run scripts from https://github.com/v2fly/fhs-install-v2ray to install v2ray core and geo file 38 | bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) 39 | bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-dat-release.sh) 40 | 41 | # write v2ray config 42 | cat > /usr/local/etc/v2ray/config.json << "EOF" 43 | { 44 | "inbounds": [{ 45 | "port": 60000, 46 | "protocol": "vmess", 47 | "settings": { 48 | "clients": [{ "id": "4cce13cd-770e-4b5b-8013-c16b6e62bbcc" }] 49 | }, 50 | "streamSettings": { 51 | "network": "ws", 52 | "wsSettings": { 53 | "path": "/v2" 54 | } 55 | } 56 | }], 57 | "outbounds": [{ 58 | "protocol": "freedom", 59 | "settings": {} 60 | }] 61 | } 62 | EOF 63 | 64 | service v2ray restart 65 | 66 | # hook certbot with nginx 67 | if ! certbot --nginx; then 68 | echo "certbot 设置出现问题,安装失败" 69 | exit 1 70 | fi 71 | 72 | # nginx reverse proxy setting 73 | setting=$( 74 | cat << "EOF" 75 | location /v2 { 76 | proxy_redirect off; 77 | proxy_pass http://127.0.0.1:60000; 78 | proxy_http_version 1.1; 79 | proxy_set_header Upgrade $http_upgrade; 80 | proxy_set_header Connection "upgrade"; 81 | proxy_set_header Host $http_host; 82 | proxy_set_header X-Real-IP $remote_addr; 83 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 84 | } 85 | EOF 86 | ) 87 | 88 | # find the first occurence of "managed by Certbot" and insert setting after it 89 | lineNumber=$(grep -in "managed by Certbot" /etc/nginx/default | awk -F':' '(NR==1){print $1}') 90 | echo "prepare to insert nginx setting at line $lineNumber" 91 | result=$(awk -v ln="$lineNumber" -v setting="$setting" 'NR==ln{print setting}1') 92 | echo "$result" > /etc/nginx/default 93 | echo "nginx setting inserted" 94 | 95 | service nginx restart 96 | -------------------------------------------------------------------------------- /utils/distro.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # get distro 4 | # supported distros: Ubuntu, macOS 5 | # output: distro name 6 | 7 | function getDistro() { 8 | local distro 9 | if [[ -e /etc/os-release ]]; then 10 | # Linux has /etc/os-release file 11 | # shellcheck disable=SC1091 12 | source /etc/os-release 13 | # /etc/os-release when sourced, will add the $NAME environment variable 14 | if echo "$NAME" | grep -iq ubuntu; then 15 | distro="Ubuntu" 16 | fi 17 | elif [[ $(uname) == "Darwin" ]]; then 18 | distro="macOS" 19 | else 20 | echo "Sorry, this script only support Ubuntu & macOS" 21 | exit 1 22 | fi 23 | echo "$distro" 24 | } 25 | 26 | -------------------------------------------------------------------------------- /utils/err.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | function err() { 4 | echo "$1" >&2 5 | } 6 | -------------------------------------------------------------------------------- /utils/header.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | function header() { 4 | echo -e "\n** $1 **\n" 5 | } 6 | --------------------------------------------------------------------------------