Organises things

Mainly organising aliases and functions, also adds some environment
variables
master
Jonathan Hodgson 4 years ago
parent f8249886c3
commit 170ecf906d
  1. 324
      shells/shared/aliases
  2. 14
      shells/shared/environmentVariables
  3. 254
      shells/shared/functions

@ -1,61 +1,37 @@
# These alow me to easily set the file and folder permissions for a wordpress instilation. ##########################
alias folder-perms='find . -type d -not -path "./.git/*" -not -path "./.git" -not -path "./node_modules/*" -not -path "./node_modules" -not -perm 775 -exec chmod 775 {} \;' # Add flags by default #
alias file-perms='find . -type f -not -path "./.git/*" -not -path "./.git" -not -path "./node_modules/*" -not -path "./node_modules" -not -perm 664 -exec chmod 664 {} \;' ##########################
alias wp-perms='folder-perms; file-perms'
alias magentoPerms='cd ${PWD%/public_html*}/public_html;sudo chown -R jonathan:http .; folder-perms; file-perms; chmod +x bin/*; cd -'
alias upgr='magento setup:upgrade && magento setup:di:compile && magentoPerms'
#
# Make ls add Indicator#s to file names and colour the output
alias ls='ls -F --color=auto'
# Make tree add indicators and color #Always make all directories necesary
alias tree='tree -F -C' alias mkdir='mkdir -p'
# Make qmv open on 1 column mode # Make qmv open on 1 column mode
alias qmv='qmv -f do' alias qmv='qmv -f do'
alias msfconsole="( systemctl status --no-pager postgresql.service > /dev/null || (echo \"Statring postgres\"; sudo systemctl start postgresql.service) ); ( pass show system/metasploit/database.yaml > database.yaml; sudo msfconsole -y database.yaml; rm database.yaml )" #An alias for my standard less configuration I don't set it to lessc because
#sometimes I don't use this config and I always forget how to ignore an alias
#Start cups #alias myless='lessc --clean-css
alias cups='sudo systemctl start org.cups.cupsd.service' #--source-map-basepath=/home/jonathan/Sites/charts/public_html --source-map
#--autoprefix="last 3 versions, ie >= 9" styles.less styles.min.css'
#Start network manager alias myless='lessc --clean-css --source-map --autoprefix="last 3 versions, ie >= 11" styles.less styles.min.css'
alias net='sudo systemctl start NetworkManager.service'
# Alias lampp because I don't want to clog my PATH
#alias lampp='/opt/lampp/lampp'
#alias glampp='gksudo /opt/lampp/manager-linux-x64.run'
#alias php='/opt/lampp/bin/php'
#alias php-cgi='/opt/lampp/bin/php-cgi'
#alias php-config='/opt/lampp/bin/php-config'
#Always make all directories necesary # Always make grep ouput color
alias mkdir='mkdir -p' alias grep="grep --color=auto"
# Shortcut for rewriting wp permalinks #Make the cal command default to start on Sunday
alias perms='wp rewrite flush' alias cal='cal -s'
#Clear terminal and try to get moon phase. If it takes longer than .5 seconds then it will show neofetch # Makes jq use colour
alias cls='clear; timeout 0.5s weather moon || neofetch' alias jq="jq -C"
#An alias for my standard less configuration # Use the config files I want
#I don't set it to lessc because sometimes I don't use this config and I always forget how to ignore an alias alias mbsync="mbsync -c \"$XDG_CONFIG_HOME/isync/mbsyncrc.secret\""
#alias myless='lessc --clean-css --source-map-basepath=/home/jonathan/Sites/charts/public_html --source-map --autoprefix="last 3 versions, ie >= 9" styles.less styles.min.css' alias imapfilter="imapfilter -c \"$XDG_CONFIG_HOME/imapfilter/config.lua\""
alias myless='lessc --clean-css --source-map --autoprefix="last 3 versions, ie >= 11" styles.less styles.min.css'
# Git shortcuts
alias status='git status '
alias st='git status'
alias checkout='git checkout'
alias ch='git checkout'
alias push='git push '
alias pull='git pull '
alias bb='git open'
alias merge='git merge'
alias mg='git merge'
# Always make grep ouput color ####################
alias grep="grep --color=auto" # Path Shortcuts #
####################
# Shortcuts to sites folder # Shortcuts to sites folder
alias sites="cd ~/Sites" alias sites="cd ~/Sites"
@ -75,45 +51,20 @@ alias db="cd ~/Dropbox/"
alias home="cd ~/" alias home="cd ~/"
alias ~="cd ~/" alias ~="cd ~/"
#Goes up to the public_html folder
alias ph='cd ${${PWD%/public_html*}%/wiki*}/public_html'
alias wiki='cd ${${PWD%/public_html*}%/wiki*}/wiki'
#Edit wp-config.php using $EDITOR
alias conf='$EDITOR ${PWD%/public_html*}/public_html/wp-config.php'
# Quit the terminal using :q (The same as Vi/Vim)
alias :q='exit;'
alias q='exit;'
# Not sure why and how but this makes sudo work with my aliases
alias sudo='sudo '
#Make the cal command default to start on Sunday
alias cal='cal -s'
# update the third party wordpress plugins we are mirroring
alias u3p='update3rdPartyPlugins'
# Edit my bashrc
alias brc='$EDITOR ~/.bashrc'
# Edit my vimrc
alias vrc='$EDITOR ~/.vimrc'
# Go to my .vim folder # Go to my .vim folder
alias .v='cd ~/.vim/' alias .v='cd ~/.vim/'
alias df='cd ~/.dotfiles' # Got to my dotfiles folder
alias .f='cd ~/.dotfiles'
#Make vim start in server mode # Edit my vimrc
#alias vim='vim --servername jab2870' alias vrc='$EDITOR ~/.dotfiles/vim/.vim/vimrc'
# moon phase
alias moonphase='weather moon'
#Get arch news
alias archNews='w3m https://www.archlinux.org/ | sed -n "/Latest News/,/Older News/ p" | head -n -1 | less' ####################
# Radio Stations #
####################
#Radio Stations #Radio Stations
AUDIO="mpv --input-ipc-server=/tmp/mpvsocket" AUDIO="mpv --input-ipc-server=/tmp/mpvsocket"
@ -123,63 +74,101 @@ alias classic="$AUDIO http://icy-e-bab-04-cr.sharp-stream.com/absoluteradio.mp3"
alias absolute="$AUDIO 'http://network.absoluteradio.co.uk/core/audio/mp3/live.pls?service=vrbb'" alias absolute="$AUDIO 'http://network.absoluteradio.co.uk/core/audio/mp3/live.pls?service=vrbb'"
alias magic="$AUDIO 'http://www.radiofeeds.co.uk/bauer.pls?station=magicnational.mp3.m3u'" alias magic="$AUDIO 'http://www.radiofeeds.co.uk/bauer.pls?station=magicnational.mp3.m3u'"
alias bs="curl -s http://cbsg.sourceforge.net/cgi-bin/live | grep -Eo '^<li>.*</li>' | sed -r -e 's/<\/?li>//g' | shuf -n 1 | cowsay" ##########
# sudo #
##########
#
# Not sure why and how but this makes sudo work with my aliases
alias sudo='sudo '
alias jq="jq -C" # Being in the docker group is essentually being root so use sudo instead
# https://github.com/moby/moby/issues/9976
alias docker="sudo docker"
alias docker-compose="sudo docker-compose"
alias debugBuild='node --inspect-brk /usr/bin/grunt build' ###################
# Upgrade tools #
###################
# This section is for tools that replace common tools
# I only do this if the flag syntax is the same of very similar
#alias lc="colorls -r" # If exa is available, alias ls to exa, otherwise alias to ls with colour and
# indicators
type -p exa > /dev/null && alias ls="exa -F" || alias ls='ls -F --color=auto'
type -p exa > /dev/null && alias l="exa -lahg --git --grid" || alias l="ls -lah"
#alias open="$TERMINAL & disown" # Make tree add indicators and color
# If exa is available, use it instead
type -p exa > /dev/null && alias tree="exa -FT" || alias tree='tree -F -C'
#audiable to mp3 # Alias cat to bat if it's available
alias aa2mp3='ffmpeg -f concat -safe 0 -i <(for f in *.aa; do echo "file '"'"'$(pwd)/$f'"'"'";done) output.mp3' type -p bat > /dev/null && alias cat="bat"
# Fix Typos # If nvim is available, alias vim to neovim
alias cim="vim" type -p nvim > /dev/null && alias vim="nvim"
alias vom="vim"
alias vin="vim"
alias vi="vim"
alias v="vim"
# Updates time using ntp # Trash instead of rm
alias updateTime="sudo ntpd -qg" type -p rmtrash > /dev/null && alias rm="rmtrash"
type -p rmdirtrash > /dev/null && alias rmdir="rmdirtrash"
# Keyboard - reset
# Sometimes, if I turn the screens off, the keyboard resets itself to defaults. Not sure why but this will put my keyboard back to how I like it
#alias kb="xmodmap ~/.Xmodmap; xset r rate 200 70; xcape"
alias kb="setxkbmap -layout gb,gb -variant \"colemak,\" -option grp:shifts_toggle; xset r rate 200 70; xinput --list | grep -E 'ErgoDox EZ ErgoDox EZ\s+id' | grep -oE 'id=[0-9]+' | cut -d'=' -f2 | xargs setxkbmap -layout gb -device"
alias colemak="setxkbmap -layout gb,gb -variant \"colemak,\" -option grp:shifts_toggle" # These don't have the same syntax but I want to be reminded of the better
alias qwerty="setxkbmap -layout gb" # versions
type mycli > /dev/null && alias mysql="echo \"You might want to use mycli instead\"; /usr/bin/mysql"
type pgcli > /dev/null && alias postgres="echo \"You might want to use pgcli instead\"; /usr/bin/postgres"
alias ol="open-local" ###################
# Git Shortcuts #
###################
alias globalip="drill myip.opendns.com @resolver1.opendns.com | sed -n '/ANSWER SECTION/,/AUTHORITY SECTION/ p' | sed -n '2 p' | awk '{print \$5}'" alias status='git status '
alias st='git status'
alias checkout='git checkout'
alias ch='git checkout'
alias push='git push '
alias pull='git pull '
alias bb='git open'
alias merge='git merge'
alias mg='git merge'
alias switch='git switch'
alias sw='git switch'
alias ss="tail -n +2 /usr/share/exploitdb/files_exploits.csv | awk -F ',' '{print \$2 \"\t\" \$3 \"\t(\" \$1 \")\"}' | fzf --preview-window=up --preview='echo {} | cut -d\" \" -f1 | xargs echo \"/usr/share/exploitdb/\" | tr -d \" \" | xargs bat --color=always' | cut -d' ' -f3 | tr -d \"()\" | xargs searchsploit -m" #######################
# typos / shortcuts #
#######################
alias ddg="ddgr" alias vim="nvim"
alias cim="nvim"
alias vom="nvim"
alias vin="nvim"
alias vi="nvim"
alias v="nvim"
alias docker="sudo docker" alias cls="clear"
alias docker-compose="sudo docker-compose" #Clear terminal and try to get moon phase. If it takes longer than .5 seconds then it will show neofetch
#alias cls='clear; timeout 0.5s weather moon || neofetch'
# Quit the terminal using :q (The same as Vi/Vim)
alias :q='exit;'
alias q='exit;'
type rmtrash > /dev/null && alias rm="rmtrash" alias rnc="resize-netcat-listener -r $HOME/go/src/resize-nc-listener/examples/stty-resize-copy"
type rmdirtrash > /dev/null && alias rmdir="rmdirtrash"
alias rs="rofi-reverse-shells" ################
# Pentesting #
################
# Armory Aliases # Start postgres for msfconsole
# In time, use docker instead
alias msfconsole="( systemctl status --no-pager postgresql.service > /dev/null || (echo \"Statring postgres\"; sudo systemctl start postgresql.service) ); ( pass show system/metasploit/database.yaml > database.yaml; sudo msfconsole -y database.yaml; rm database.yaml )"
alias ss="tail -n +2 /usr/share/exploitdb/files_exploits.csv | awk -F ',' '{print \$2 \"\t\" \$3 \"\t(\" \$1 \")\"}' | fzf --preview-window=up --preview='echo {} | cut -d\" \" -f1 | xargs echo \"/usr/share/exploitdb/\" | tr -d \" \" | xargs bat --color=always' | cut -d' ' -f3 | tr -d \"()\" | xargs searchsploit -m"
ARMORY="$HOME/GitRepos/armoury" ARMORY="$HOME/GitRepos/armoury"
alias surecheckImport="$JAVA_HOME/bin/java -jar $ARMORY/host_build_reviews/windows/SurecheckImport/SurecheckImport_v0.2.jar " alias surecheckImport="$JAVA_HOME/bin/java -jar $ARMORY/host_build_reviews/windows/SurecheckImport/SurecheckImport_v0.2.jar "
alias rot13="tr 'A-Za-z' 'N-ZA-Mn-za-m'" alias rot13="tr 'A-Za-z' 'N-ZA-Mn-za-m'"
type mycli > /dev/null && alias mysql="echo \"You might want to use mycli instead\"; /usr/bin/mysql"
type pgcli > /dev/null && alias postgres="echo \"You might want to use pgcli instead\"; /usr/bin/postgres"
# These aliases are related to projects # These aliases are related to projects
# Make sqlmap put output in the current project folder # Make sqlmap put output in the current project folder
alias sqlmap="[ -L ~/Projects/current ] && sqlmap --output-dir=\"~/Projects/current/sqlmap\"" alias sqlmap="[ -L ~/Projects/current ] && sqlmap --output-dir=\"~/Projects/current/sqlmap\""
@ -192,13 +181,112 @@ alias pc="project switch --fzf"
# Create a new project # Create a new project
alias pn="project new" alias pn="project new"
alias tl="tldr -a | tr ',' '\n' | tr -d ' ' | fzf --preview='tldr {} -m | bat -l markdown --color always' | xargs tldr -m | bat -l markdown --color always"
alias snmp-check="/usr/bin/snmpcheck-nothink" alias snmp-check="/usr/bin/snmpcheck-nothink"
alias chrome-curl="node $HOME/GitRepos/chrome-curl/index.js"
#alias irmgpg="gpg --no-default-keyring --keyring=irm.gpg" #alias irmgpg="gpg --no-default-keyring --keyring=irm.gpg"
alias irmgpg="gpg --options ~/.gnupg/irmgpg.conf --keyring=irm.gpg" alias irmgpg="gpg --options ~/.gnupg/irmgpg.conf --keyring=irm.gpg"
alias weakopenssl="$HOME/GitRepos/openssl-weak/openssl-1.0.2-chacha/apps/openssl" alias weakopenssl="$HOME/GitRepos/openssl-weak/openssl-1.0.2-chacha/apps/openssl"
##############
# Keyboard #
##############
# Keyboard - reset
# Sometimes, if I turn the screens off, the keyboard resets itself to defaults. Not sure why but this will put my keyboard back to how I like it
#alias kb="xmodmap ~/.Xmodmap; xset r rate 200 70; xcape"
alias kb="setxkbmap -layout gb,gb -variant \"colemak,\" -option grp:shifts_toggle; xset r rate 200 70; xinput --list | grep -Ei 'ErgoDox EZ\s+id' | grep -oE 'id=[0-9]+' | cut -d'=' -f2 | xargs setxkbmap -layout gb -device"
alias colemak="setxkbmap -layout gb,gb -variant \"colemak,\" -option grp:shifts_toggle"
alias qwerty="setxkbmap -layout gb"
#################
# Web Searches #
#################
alias ws="websearch"
alias aw="websearch aw"
alias wiki="websearch wiki"
alias aur="websearch aur"
alias ddg="BROWSER=\"w3m\" ddgr"
#
#############
# Web Dev #
#############
# These alow me to easily set the file and folder permissions for a wordpress instilation.
alias folder-perms='find . -type d -not -path "./.git/*" -not -path "./.git" -not -path "./node_modules/*" -not -path "./node_modules" -not -perm 775 -exec chmod 775 {} \;'
alias file-perms='find . -type f -not -path "./.git/*" -not -path "./.git" -not -path "./node_modules/*" -not -path "./node_modules" -not -perm 664 -exec chmod 664 {} \;'
alias wp-perms='folder-perms; file-perms'
# Same for Magento
alias magentoPerms='cd ${PWD%/public_html*}/public_html;sudo chown -R jonathan:http .; folder-perms; file-perms; chmod +x bin/*; cd -'
alias magentoUpgr='magento setup:upgrade && magento setup:di:compile && magentoPerms'
# Shortcut for rewriting wp permalinks
alias perms='wp rewrite flush'
#Goes up to the public_html folder
alias ph='cd ${${PWD%/public_html*}%/wiki*}/public_html'
alias wiki='cd ${${PWD%/public_html*}%/wiki*}/wiki'
#Edit wp-config.php using $EDITOR
alias wpconf='$EDITOR ${PWD%/public_html*}/public_html/wp-config.php'
##########
# Misc #
##########
#Start cups
alias cups='sudo systemctl start org.cups.cupsd.service'
# moon phase
alias moonphase='weather moon'
#audiable to mp3
alias aa2mp3='ffmpeg -f concat -safe 0 -i <(for f in *.aa; do echo "file '"'"'$(pwd)/$f'"'"'";done) output.mp3'
# Updates time using ntp
alias updateTime="sudo ntpd -qg"
alias globalip="drill myip.opendns.com @resolver1.opendns.com | sed -n '/ANSWER SECTION/,/AUTHORITY SECTION/ p' | sed -n '2 p' | awk '{print \$5}'"
alias chrome-curl="node $HOME/GitRepos/chrome-curl/index.js"
if type grc > /dev/null 2>&1; then
for cmd in "nmap" "ping" "traceroute" "mount" "netstat" "ps" "dig" "du" "df" "ip" "iptables" "lsblk" "id" "free" "tcpdump" "uptime" "showmount" "whois" ; do
alias "$cmd"="grc $(whence $cmd)"
alias "${cmd}c"="grc --colour=on $(whence $cmd)"
done
fi

@ -1,9 +1,12 @@
export LANG="en_GB.UTF-8" export LANG="en_GB.UTF-8"
export TERMINAL=/usr/local/bin/st export TERMINAL=/usr/local/bin/st
export TERM=xterm-256color export TERM=xterm-256color
export EDITOR='vim' type -p nvim > /dev/null && export EDITOR="nvim" || export EDITOR="vim"
export READER='zathura' export READER='zathura'
export BROWSER="firefox-developer-edition"
export CDPATH=.:~:~/Projects:~/.dotfiles export CDPATH=.:~:~/Projects:~/.dotfiles
export GOPATH="$HOME/go"
export NODE_PATH='/usr/lib/node_modules/'
#Adds a list of all the sub directories in my .bin folder to a variable called mypath #Adds a list of all the sub directories in my .bin folder to a variable called mypath
mypath="$HOME/.bin" mypath="$HOME/.bin"
@ -12,7 +15,7 @@ for d in "$HOME"/.bin/*/; do
mypath+=":$d" mypath+=":$d"
done done
export PATH=~/Projects/current/bin:$mypath:$PATH:. export PATH=~/Projects/current/bin:$mypath:$GOPATH/bin:$PATH:.
#Ruby things #Ruby things
GEM_HOME=$(ls -t -U | ruby -e 'puts Gem.user_dir') GEM_HOME=$(ls -t -U | ruby -e 'puts Gem.user_dir')
@ -20,6 +23,13 @@ GEM_PATH=$GEM_HOME
export PATH=$PATH:$GEM_HOME/bin export PATH=$PATH:$GEM_HOME/bin
export GEM_HOME=$(ruby -e 'print Gem.user_dir') export GEM_HOME=$(ruby -e 'print Gem.user_dir')
export PATH=$PATH:$HOME/node_modules/.bin
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_DATA_HOME="$HOME/.local/share"
export NOTMUCH_CONFIG="${XDG_CONFIG_HOME}/notmuch/config"
export LESS_TERMCAP_mb=$'\e[1;36m' export LESS_TERMCAP_mb=$'\e[1;36m'
export LESS_TERMCAP_md=$'\e[1;36m' export LESS_TERMCAP_md=$'\e[1;36m'

@ -1,14 +1,6 @@
function big-chromium () {
chromium --force-device-scale-factor=$1
}
function big-new-chromium () {
chromium-snapshot-bin --force-device-scale-factor=$1
}
# make xclip work as I would expect. Copy to clipboard if piped data. Paste from otherwise # make xclip work as I would expect. Copy to clipboard if piped data. Paste from otherwise
function clip(){ function clip(){
if command -v /usr/bin/xclip 1>/dev/null; then if type -p /usr/bin/xclip >/dev/null; then
if [[ -p /dev/stdin ]] ; then if [[ -p /dev/stdin ]] ; then
# stdin is a pipe # stdin is a pipe
# stdin -> clipboard # stdin -> clipboard
@ -25,66 +17,162 @@ fi
#Swap two files #Swap two files
function swap() { function swap() {
mv $1 $1._tmp; [ -e "$1._tmp" ] && return
mv $2 $1; mv "$1" "$1._tmp"
mv $1._tmp $2; mv "$2" "$1"
mv "$1._tmp" "$2"
} }
# Add old extention
function old() { function old() {
mv "$1" "$1.old" for file in "$@"; do
mv "$file" "$file.old"
done
} }
function mycd() { # Cd that does what I normally want
cd "$@" 2> /dev/null function cd() {
# Try a normal cd
builtin cd "$@" 2> /dev/null
if [ $? = 0 ]; then if [ $? = 0 ]; then
# If we get here cd was successful # If we get here cd was successful so do a ls
ls ls
else else
# If we get here, cd was not successful # If we get here, cd was not successful
if [ -f "$1" ]; then if [ -f "$1" ]; then
# If there is a file there, try and open it in vim
# ToDo: smarter open so it will open in zathura if it's a pdf for
# example
$EDITOR "$1" $EDITOR "$1"
else else
# Otherwise fail clearly
echo "Can't cd" echo "Can't cd"
fi fi
fi fi
#updatePath #updatePath
} }
alias cd="mycd"
# Make a folder then cd into it
function mkcd() { function mkcd() {
mkdir -p "$1" mkdir -p "$1"
cd "$1" cd "$1"
} }
function createLetter(){ # Adds sub folders in by .bin directory to the PATH if they are not already in it
if [ "$1" ]; then # Also adds .bin to the path adjacent to any public_html folder
if [ "$2" ]; then function updatePath(){
newFile="$2" # Reset the path
else PATH=$(echo $PATH | sed -E "s/:\/home\/jonathan\/\.bin\/.*//g")
newFile="$1" for d in ~/.bin/*/; do
newFile="${newFile%.*}.pdf" if [[ :$PATH: != *:"$d":* ]] ; then
PATH+=":$d"
fi fi
pandoc --template template-letter.tex $1 -o $newFile done
else public_html=${PWD%/public_html*}/public_html
echo "Oops. You need to suply a file" if [ -d $public_html ]; then
return 1 PATH+=":${PWD%/public_html*}/.bin"
fi fi
} }
function createFPLreport(){ function reset_colourscheme(){
if [ "$1" ]; then if [ -L $HOME/.dotfiles/shells/zsh/current-color-scheme ]; then
if [ "$2" ]; then source $HOME/.dotfiles/shells/zsh/current-color-scheme
newFile="$2" fi
else exit 2
newFile="$1" }
newFile="${newFile%.*}.pdf"
# If running ssh interactively (not tab completion) change the colour scheme
function ssh(){
if [[ -t 0 ]]; then
if [ -L $HOME/.dotfiles/shells/zsh/ssh-color-scheme ]; then
source $HOME/.dotfiles/shells/zsh/ssh-color-scheme
trap "reset_colourscheme" 2
fi
fi
command /usr/bin/ssh "$@"
if [[ -t 0 ]]; then
if [ -L $HOME/.dotfiles/shells/zsh/current-color-scheme ]; then
source $HOME/.dotfiles/shells/zsh/current-color-scheme
fi
fi
}
# Turn on a proxy
# Note that this is not fool proof. It is up to applications to check the
# environment variables
function proxy_on() {
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
if (( $# > 0 )); then
valid=$(echo $@ | sed -n 's/\([0-9]\{1,3\}.\?\)\{4\}:\([0-9]\+\)/&/p')
if [[ $valid != $@ ]]; then
>&2 echo "Invalid address"
return 1
fi fi
pandoc --template fellowship.latex --listings --highlight-style=pygments --pdf-engine=xelatex $1 -o $newFile local proxy=$1
export http_proxy="$proxy" \
https_proxy=$proxy \
ftp_proxy=$proxy \
rsync_proxy=$proxy
echo "Proxy environment variable set."
return 0
fi
echo -n "username: "; read username
if [[ $username != "" ]]; then
echo -n "password: "
read -es password
local pre="$username:$password@"
fi
echo -n "server: "; read server
echo -n "port: "; read port
local proxy=$pre$server:$port
export http_proxy="$proxy" \
https_proxy=$proxy \
ftp_proxy=$proxy \
rsync_proxy=$proxy \
HTTP_PROXY=$proxy \
HTTPS_PROXY=$proxy \
FTP_PROXY=$proxy \
RSYNC_PROXY=$proxy
}
function proxy_off(){
unset http_proxy https_proxy ftp_proxy rsync_proxy \
HTTP_PROXY HTTPS_PROXY FTP_PROXY RSYNC_PROXY
echo -e "Proxy environment variable removed."
}
# Sanity check for dd
function dd(){
local drive="$(echo "$@" | grep -oE 'of=[^ ]+' | cut -d '=' -f 2-)"
if [ -n "$drive" ]; then
if mount | grep -q "$drive"; then
echo "It looks like that's mounted, probably not the drive you're after"
echo "If you are sure, run /usr/bin/dd ..."
return 1
fi
fi
/usr/bin/dd "$@"
}
# Man without options will use fzf to select a page
function man(){
MAN="/usr/bin/man"
if [ -n "$1" ]; then
$MAN "$@"
return $?
else else
echo "Oops. You need to suply a file" $MAN -k . | fzf --reverse --preview="echo {1,2} | sed 's/ (/./' | sed -E 's/\)\s*$//' | xargs $MAN" | awk '{print $1 "." $2}' | tr -d '()' | xargs -r $MAN
return 1 return $?
fi fi
} }
#
#######################
# Wordpress Helpers #
#######################
#Takes you to the parent theme #Takes you to the parent theme
function ptheme() { function ptheme() {
@ -218,93 +306,3 @@ function debugToggle(){
fi fi
} }
# Adds sub folders in by .bin directory to the PATH if they are not already in it
# Also adds .bin to the path adjacent to any public_html folder
function updatePath(){
# Reset the path
PATH=$(echo $PATH | sed -E "s/:\/home\/jonathan\/\.bin\/.*//g")
for d in ~/.bin/*/; do
if [[ :$PATH: != *:"$d":* ]] ; then
PATH+=":$d"
fi
done
public_html=${PWD%/public_html*}/public_html
if [ -d $public_html ]; then
PATH+=":${PWD%/public_html*}/.bin"
fi
}
function reset_colourscheme(){
if [ -L $HOME/.dotfiles/shells/zsh/current-color-scheme ]; then
source $HOME/.dotfiles/shells/zsh/current-color-scheme
fi
exit 2
}
function ssh(){
if [ -L $HOME/.dotfiles/shells/zsh/ssh-color-scheme ]; then
source $HOME/.dotfiles/shells/zsh/ssh-color-scheme
fi
trap "reset_colourscheme" 2
command /usr/bin/ssh "$@"
if [ -L $HOME/.dotfiles/shells/zsh/current-color-scheme ]; then
source $HOME/.dotfiles/shells/zsh/current-color-scheme
fi
}
function proxy_on() {
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
if (( $# > 0 )); then
valid=$(echo $@ | sed -n 's/\([0-9]\{1,3\}.\?\)\{4\}:\([0-9]\+\)/&/p')
if [[ $valid != $@ ]]; then
>&2 echo "Invalid address"
return 1
fi
local proxy=$1
export http_proxy="$proxy" \
https_proxy=$proxy \
ftp_proxy=$proxy \
rsync_proxy=$proxy
echo "Proxy environment variable set."
return 0
fi
echo -n "username: "; read username
if [[ $username != "" ]]; then
echo -n "password: "
read -es password
local pre="$username:$password@"
fi
echo -n "server: "; read server
echo -n "port: "; read port
local proxy=$pre$server:$port
export http_proxy="$proxy" \
https_proxy=$proxy \
ftp_proxy=$proxy \
rsync_proxy=$proxy \
HTTP_PROXY=$proxy \
HTTPS_PROXY=$proxy \
FTP_PROXY=$proxy \
RSYNC_PROXY=$proxy
}
function proxy_off(){
unset http_proxy https_proxy ftp_proxy rsync_proxy \
HTTP_PROXY HTTPS_PROXY FTP_PROXY RSYNC_PROXY
echo -e "Proxy environment variable removed."
}
function man(){
MAN="/usr/bin/man"
if [ -n "$1" ]; then
$MAN "$@"
return $?
else
$MAN -k . | fzf --reverse --preview="echo {1,2} | sed 's/ (/./' | sed -E 's/\)\s*$//' | xargs $MAN" | awk '{print $1 "." $2}' | tr -d '()' | xargs -r $MAN
return $?
fi
}
#alias man="myman"

Loading…
Cancel
Save