Last active
November 26, 2020 02:43
-
-
Save infinex/cc3e508d8def96b165b716f4d3dd6a68 to your computer and use it in GitHub Desktop.
shell
This file contains hidden or 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
| z() { | |
| if [[ "$#" -ne 0 ]]; then | |
| cd $(autojump $@) | |
| return | |
| fi | |
| cd "$(autojump -s | sort -k1gr | awk '$1 ~ /[0-9]:/ && $2 ~ /^\// { for (i=2; i<=NF; i++) { print $(i) } }' | fzf --height 40% --reverse --inline-info)" | |
| } | |
| k() { | |
| local pid | |
| pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}') | |
| if [ "x$pid" != "x" ] | |
| then | |
| echo $pid | xargs kill -${1:-9} | |
| fi | |
| } | |
| fif() { | |
| if [ ! "$#" -gt 0 ]; then echo "Need a input string";return 1; fi | |
| rg --files-with-matches --no-messages "$1" | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 '$1' || rg --ignore-case --pretty --context 10 '$1' {}" | |
| } | |
| # Create a new directory and enter it | |
| function md() { | |
| mkdir -p "$@" && cd "$@" | |
| } | |
| # find shorthand | |
| function f() { | |
| find . -name "$1" 2>&1 | grep -v 'Permission denied' | |
| } | |
| function la(){ | |
| ls -l "$@" | awk ' | |
| { | |
| k=0; | |
| for (i=0;i<=8;i++) | |
| k+=((substr($1,i+2,1)~/[rwx]/) *2^(8-i)); | |
| if (k) | |
| printf("%0o ",k); | |
| printf(" %9s %3s %2s %5s %6s %s %s %s\n", $3, $6, $7, $8, $5, $9,$10, $11); | |
| }' | |
| } | |
| cdf() { # short for cdfinder | |
| cd "`osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)'`" | |
| } | |
| function csvpreview(){ | |
| sed 's/,,/, ,/g;s/,,/, ,/g' "$@" | column -s, -t | less -#2 -N -S | |
| } | |
| function ex() { | |
| if [ -f "$1" ] ; then | |
| local filename=$(basename "$1") | |
| local foldername="${filename%%.*}" | |
| local fullpath=`perl -e 'use Cwd "abs_path";print abs_path(shift)' "$1"` | |
| local didfolderexist=false | |
| if [ -d "$foldername" ]; then | |
| didfolderexist=true | |
| read -p "$foldername already exists, do you want to overwrite it? (y/n) " -n 1 | |
| echo | |
| if [[ $REPLY =~ ^[Nn]$ ]]; then | |
| return | |
| fi | |
| fi | |
| mkdir -p "$foldername" && cd "$foldername" | |
| case $1 in | |
| *.tar.bz2) tar xjf "$fullpath" ;; | |
| *.tar.gz) tar xzf "$fullpath" ;; | |
| *.tar.xz) tar Jxvf "$fullpath" ;; | |
| *.tar.Z) tar xzf "$fullpath" ;; | |
| *.tar) tar xf "$fullpath" ;; | |
| *.taz) tar xzf "$fullpath" ;; | |
| *.tb2) tar xjf "$fullpath" ;; | |
| *.tbz) tar xjf "$fullpath" ;; | |
| *.tbz2) tar xjf "$fullpath" ;; | |
| *.tgz) tar xzf "$fullpath" ;; | |
| *.txz) tar Jxvf "$fullpath" ;; | |
| *.zip) unzip "$fullpath" ;; | |
| *) echo "'$1' cannot be extracted via extract()" && cd .. && ! $didfolderexist && rm -r "$foldername" ;; | |
| esac | |
| else | |
| echo "'$1' is not a valid file" | |
| fi | |
| } | |
| function code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCodeInsiders" --args $*; } | |
| alias ..="cd .." | |
| alias cd..="cd .." | |
| alias ..2="cd ../.." | |
| alias ..3="cd ../../.." | |
| alias ..4="cd ../../../.." | |
| alias ~="cd ~" # `cd` is probably faster to type though | |
| alias -- -="cd -" | |
| alias c="cat" | |
| alias mv='mv -v' | |
| alias rm='rm -i -v' | |
| alias cp='cp -v' | |
| alias chmox='chmod -x' | |
| alias hosts='sudo $EDITOR /etc/hosts' # yes I occasionally 127.0.0.1 twitter.com ;) | |
| alias lsd='ls -l | grep "^d"' # only directories | |
| alias cleanup_dsstore="find . -name '*.DS_Store' -type f -ls -delete" | |
| alias diskspace_report="df -P -kHl" | |
| alias free_diskspace_report="diskspace_report" | |
| alias wget="curl -O" | |
| alias ip="dig +short myip.opendns.com @resolver1.opendns.com" | |
| alias g="git" | |
| alias v="vim" | |
| alias ds='du -d 1 -h' | |
| alias ls='ls --color=auto' | |
| alias ll='ls --color=auto -al' | |
| alias l='exa --group-directories-first' | |
| alias ll='exa -lg --group-directories-first' | |
| alias la='exa -lag --group-directories-first' | |
| alias lm='exa -lgs modified --group-directories-first' | |
| alias lmr='exa -lgs modified --group-directories-first --reverse' | |
| alias ols="ls -la --color | awk '{k=0;for(i=0;i<=8;i++)k+=((substr(\$1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(\" %0o \",k);print}'" | |
| alias hr='printf $(printf "\e[$(shuf -i 91-97 -n 1);1m%%%ds\e[0m\n" $(tput cols)) | tr " " =' | |
| alias please='sudo $(history -p !!)' | |
| alias pst="ps -aux | grep -i" | |
| alias pretty='column -ents $'\''\t'\''' | |
| alias .z='$EDITOR ~/.zshrc && . ~/.zshrc' | |
| alias tm="tmux -2 attach-session || tmux -2 new-session" | |
| refresh () { while true; do $@; sleep 1; clear; done; } | |
| alias webshare="python -m SimpleHTTPServer 8656" |
This file contains hidden or 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
| #!/bin/bash | |
| sshfs="sshfs nus_gpu" | |
| while true; do | |
| ps_out=`ps -ef | grep "$sshfs" | grep -v 'grep'` | |
| result=$(echo $ps_out | grep "$sshfs") | |
| if [[ "$result" != "" ]];then | |
| echo "Running" | |
| else | |
| echo "Not Running" | |
| echo "restarting" | |
| umount server/nus_gpu | |
| sshfs nus_gpu:/storage/fbzhu/.nn_framework_data/projects server/nus_gpu | |
| echo "sshfs restarted" | |
| fi | |
| sleep 10 | |
| done | |
| nohup bash process_check.sh &> /dev/null & |
This file contains hidden or 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
| from IPython import embed; embed() | |
| jupyter nbconvert --clear-output --inplace my_notebook.ipynb |
This file contains hidden or 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
| k() { | |
| local pid | |
| pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}') | |
| if [ "x$pid" != "x" ] | |
| then | |
| echo $pid | xargs kill -${1:-9} | |
| fi | |
| } | |
| fif() { | |
| if [ ! "$#" -gt 0 ]; then echo "Need a input string";return 1; fi | |
| rg --files-with-matches --no-messages "$1" | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 '$1' || rg --ignore-case --pretty --context 10 '$1' {}" | |
| } | |
| z() { | |
| if [[ "$#" -ne 0 ]]; then | |
| cd $(autojump $@) | |
| return | |
| fi | |
| cd "$(autojump -s | sort -k1gr | awk '$1 ~ /[0-9]:/ && $2 ~ /^\// { for (i=2; i<=NF; i++) { print $(i) } }' | fzf --height 40% --reverse --inline-info)" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment