mirror of
https://github.com/ohmybash/oh-my-bash.git
synced 2024-05-11 05:55:37 +00:00
lib/base: Change indentation
This commit is contained in:
294
lib/base.sh
294
lib/base.sh
@ -34,47 +34,47 @@
|
||||
|
||||
# mcd: Makes new Dir and jumps inside
|
||||
# --------------------------------------------------------------------
|
||||
mcd () { mkdir -p -- "$*" ; cd -- "$*" || exit ; }
|
||||
mcd () { mkdir -p -- "$*" ; cd -- "$*" || exit ; }
|
||||
|
||||
# mans: Search manpage given in agument '1' for term given in argument '2' (case insensitive)
|
||||
# displays paginated result with colored search terms and two lines surrounding each hit.
|
||||
# Example: mans mplayer codec
|
||||
# --------------------------------------------------------------------
|
||||
mans () { man "$1" | grep -iC2 --color=always "$2" | less ; }
|
||||
mans () { man "$1" | grep -iC2 --color=always "$2" | less ; }
|
||||
|
||||
# showa: to remind yourself of an alias (given some part of it)
|
||||
# ------------------------------------------------------------
|
||||
showa () { /usr/bin/grep --color=always -i -a1 "$@" ~/Library/init/bash/aliases.bash | grep -v '^\s*$' | less -FSRXc ; }
|
||||
showa () { /usr/bin/grep --color=always -i -a1 "$@" ~/Library/init/bash/aliases.bash | grep -v '^\s*$' | less -FSRXc ; }
|
||||
|
||||
# quiet: mute output of a command
|
||||
# ------------------------------------------------------------
|
||||
quiet () {
|
||||
"$*" &> /dev/null &
|
||||
}
|
||||
quiet () {
|
||||
"$*" &> /dev/null &
|
||||
}
|
||||
|
||||
# lsgrep: search through directory contents with grep
|
||||
# ------------------------------------------------------------
|
||||
# shellcheck disable=SC2010
|
||||
lsgrep () { ls | grep "$*" ; }
|
||||
lsgrep () { ls | grep "$*" ; }
|
||||
|
||||
# banish-cookies: redirect .adobe and .macromedia files to /dev/null
|
||||
# ------------------------------------------------------------
|
||||
banish-cookies () {
|
||||
rm -r ~/.macromedia ~/.adobe
|
||||
ln -s /dev/null ~/.adobe
|
||||
ln -s /dev/null ~/.macromedia
|
||||
}
|
||||
banish-cookies () {
|
||||
rm -r ~/.macromedia ~/.adobe
|
||||
ln -s /dev/null ~/.adobe
|
||||
ln -s /dev/null ~/.macromedia
|
||||
}
|
||||
|
||||
# show the n most used commands. defaults to 10
|
||||
# ------------------------------------------------------------
|
||||
hstats() {
|
||||
if [[ $# -lt 1 ]]; then
|
||||
NUM=10
|
||||
else
|
||||
NUM=${1}
|
||||
fi
|
||||
history | awk '{print $2}' | sort | uniq -c | sort -rn | head -"$NUM"
|
||||
}
|
||||
hstats() {
|
||||
if [[ $# -lt 1 ]]; then
|
||||
NUM=10
|
||||
else
|
||||
NUM=${1}
|
||||
fi
|
||||
history | awk '{print $2}' | sort | uniq -c | sort -rn | head -"$NUM"
|
||||
}
|
||||
|
||||
|
||||
# -------------------------------
|
||||
@ -85,74 +85,74 @@ zipf () { zip -r "$1".zip "$1" ; } # zipf: To create a ZIP arc
|
||||
|
||||
# extract: Extract most know archives with one command
|
||||
# ---------------------------------------------------------
|
||||
extract () {
|
||||
if [ -f "$1" ] ; then
|
||||
case "$1" in
|
||||
*.tar.bz2) tar xjf "$1" ;;
|
||||
*.tar.gz) tar xzf "$1" ;;
|
||||
*.bz2) bunzip2 "$1" ;;
|
||||
*.rar) unrar e "$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 extract()" ;;
|
||||
esac
|
||||
else
|
||||
echo "'$1' is not a valid file"
|
||||
fi
|
||||
}
|
||||
extract () {
|
||||
if [ -f "$1" ] ; then
|
||||
case "$1" in
|
||||
*.tar.bz2) tar xjf "$1" ;;
|
||||
*.tar.gz) tar xzf "$1" ;;
|
||||
*.bz2) bunzip2 "$1" ;;
|
||||
*.rar) unrar e "$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 extract()" ;;
|
||||
esac
|
||||
else
|
||||
echo "'$1' is not a valid file"
|
||||
fi
|
||||
}
|
||||
|
||||
# buf: back up file with timestamp
|
||||
# ---------------------------------------------------------
|
||||
buf () {
|
||||
local filename filetime
|
||||
filename=$1
|
||||
filetime=$(date +%Y%m%d_%H%M%S)
|
||||
cp -a "${filename}" "${filename}_${filetime}"
|
||||
}
|
||||
buf () {
|
||||
local filename filetime
|
||||
filename=$1
|
||||
filetime=$(date +%Y%m%d_%H%M%S)
|
||||
cp -a "${filename}" "${filename}_${filetime}"
|
||||
}
|
||||
|
||||
# del: move files to hidden folder in tmp, that gets cleared on each reboot
|
||||
# ---------------------------------------------------------
|
||||
del() {
|
||||
mkdir -p /tmp/.trash && mv "$@" /tmp/.trash;
|
||||
}
|
||||
del() {
|
||||
mkdir -p /tmp/.trash && mv "$@" /tmp/.trash;
|
||||
}
|
||||
|
||||
# mkiso: creates iso from current dir in the parent dir (unless defined)
|
||||
# ---------------------------------------------------------
|
||||
mkiso () {
|
||||
if _omb_util_command_exists mkisofs; then
|
||||
if [ -z ${1+x} ]; then
|
||||
local isoname=${PWD##*/}
|
||||
else
|
||||
local isoname=$1
|
||||
fi
|
||||
mkiso () {
|
||||
if _omb_util_command_exists mkisofs; then
|
||||
if [ -z ${1+x} ]; then
|
||||
local isoname=${PWD##*/}
|
||||
else
|
||||
local isoname=$1
|
||||
fi
|
||||
|
||||
if [ -z ${2+x} ]; then
|
||||
local destpath=../
|
||||
else
|
||||
local destpath=$2
|
||||
fi
|
||||
if [ -z ${2+x} ]; then
|
||||
local destpath=../
|
||||
else
|
||||
local destpath=$2
|
||||
fi
|
||||
|
||||
if [ -z ${3+x} ]; then
|
||||
local srcpath=${PWD}
|
||||
else
|
||||
local srcpath=$3
|
||||
fi
|
||||
if [ -z ${3+x} ]; then
|
||||
local srcpath=${PWD}
|
||||
else
|
||||
local srcpath=$3
|
||||
fi
|
||||
|
||||
if [ ! -f "${destpath}${isoname}.iso" ]; then
|
||||
echo "writing ${isoname}.iso to ${destpath} from ${srcpath}"
|
||||
mkisofs -V "${isoname}" -iso-level 3 -r -o "${destpath}${isoname}.iso" "${srcpath}"
|
||||
else
|
||||
echo "${destpath}${isoname}.iso already exists"
|
||||
fi
|
||||
else
|
||||
echo "mkisofs cmd does not exist, please install cdrtools"
|
||||
fi
|
||||
}
|
||||
if [ ! -f "${destpath}${isoname}.iso" ]; then
|
||||
echo "writing ${isoname}.iso to ${destpath} from ${srcpath}"
|
||||
mkisofs -V "${isoname}" -iso-level 3 -r -o "${destpath}${isoname}.iso" "${srcpath}"
|
||||
else
|
||||
echo "${destpath}${isoname}.iso already exists"
|
||||
fi
|
||||
else
|
||||
echo "mkisofs cmd does not exist, please install cdrtools"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------
|
||||
@ -183,11 +183,11 @@ bigfind() {
|
||||
# E.g. findPid '/d$/' finds pids of all processes with names ending in 'd'
|
||||
# Without the 'sudo' it will only find processes of the current user
|
||||
# -----------------------------------------------------
|
||||
findPid () { lsof -t -c "$@" ; }
|
||||
findPid () { lsof -t -c "$@" ; }
|
||||
|
||||
# my_ps: List processes owned by my user:
|
||||
# ------------------------------------------------------------
|
||||
my_ps() { ps "$@" -u "$USER" -o pid,%cpu,%mem,start,time,bsdtime,command ; }
|
||||
my_ps() { ps "$@" -u "$USER" -o pid,%cpu,%mem,start,time,bsdtime,command ; }
|
||||
|
||||
|
||||
# ---------------------------
|
||||
@ -196,44 +196,44 @@ bigfind() {
|
||||
|
||||
# ips: display all ip addresses for this host
|
||||
# -------------------------------------------------------------------
|
||||
ips () {
|
||||
if _omb_util_command_exists ifconfig
|
||||
then
|
||||
ifconfig | awk '/inet /{ print $2 }'
|
||||
elif _omb_util_command_exists ip
|
||||
then
|
||||
ip addr | grep -oP 'inet \K[\d.]+'
|
||||
else
|
||||
echo "You don't have ifconfig or ip command installed!"
|
||||
fi
|
||||
}
|
||||
ips () {
|
||||
if _omb_util_command_exists ifconfig
|
||||
then
|
||||
ifconfig | awk '/inet /{ print $2 }'
|
||||
elif _omb_util_command_exists ip
|
||||
then
|
||||
ip addr | grep -oP 'inet \K[\d.]+'
|
||||
else
|
||||
echo "You don't have ifconfig or ip command installed!"
|
||||
fi
|
||||
}
|
||||
|
||||
# down4me: checks whether a website is down for you, or everybody
|
||||
# -------------------------------------------------------------------
|
||||
down4me () {
|
||||
curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
|
||||
}
|
||||
down4me () {
|
||||
curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
|
||||
}
|
||||
|
||||
# myip: displays your ip address, as seen by the Internet
|
||||
# -------------------------------------------------------------------
|
||||
myip () {
|
||||
res=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+')
|
||||
echo -e "Your public IP is: ${_omb_term_bold_green} $res ${_omb_term_normal}"
|
||||
}
|
||||
myip () {
|
||||
res=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+')
|
||||
echo -e "Your public IP is: ${_omb_term_bold_green} $res ${_omb_term_normal}"
|
||||
}
|
||||
|
||||
# ii: display useful host related informaton
|
||||
# -------------------------------------------------------------------
|
||||
ii() {
|
||||
echo -e "\\nYou are logged on ${_omb_term_brown}$HOST"
|
||||
echo -e "\\nAdditionnal information:$NC " ; uname -a
|
||||
echo -e "\\n${_omb_term_brown}Users logged on:$NC " ; w -h
|
||||
echo -e "\\n${_omb_term_brown}Current date :$NC " ; date
|
||||
echo -e "\\n${_omb_term_brown}Machine stats :$NC " ; uptime
|
||||
[[ "$OSTYPE" == darwin* ]] && echo -e "\\n${_omb_term_brown}Current network location :$NC " ; scselect
|
||||
echo -e "\\n${_omb_term_brown}Public facing IP Address :$NC " ;myip
|
||||
[[ "$OSTYPE" == darwin* ]] && echo -e "\\n${_omb_term_brown}DNS Configuration:$NC " ; scutil --dns
|
||||
echo
|
||||
}
|
||||
ii() {
|
||||
echo -e "\\nYou are logged on ${_omb_term_brown}$HOST"
|
||||
echo -e "\\nAdditionnal information:$NC " ; uname -a
|
||||
echo -e "\\n${_omb_term_brown}Users logged on:$NC " ; w -h
|
||||
echo -e "\\n${_omb_term_brown}Current date :$NC " ; date
|
||||
echo -e "\\n${_omb_term_brown}Machine stats :$NC " ; uptime
|
||||
[[ "$OSTYPE" == darwin* ]] && echo -e "\\n${_omb_term_brown}Current network location :$NC " ; scselect
|
||||
echo -e "\\n${_omb_term_brown}Public facing IP Address :$NC " ;myip
|
||||
[[ "$OSTYPE" == darwin* ]] && echo -e "\\n${_omb_term_brown}DNS Configuration:$NC " ; scutil --dns
|
||||
echo
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------
|
||||
@ -242,45 +242,45 @@ bigfind() {
|
||||
|
||||
# batch_chmod: Batch chmod for all files & sub-directories in the current one
|
||||
# -------------------------------------------------------------------
|
||||
batch_chmod() {
|
||||
echo -ne "${_omb_term_bold_navy}Applying 0755 permission for all directories..."
|
||||
(find . -type d -print0 | xargs -0 chmod 0755) &
|
||||
spinner
|
||||
echo -ne "${_omb_term_normal}"
|
||||
|
||||
echo -ne "${_omb_term_bold_navy}Applying 0644 permission for all files..."
|
||||
(find . -type f -print0 | xargs -0 chmod 0644) &
|
||||
spinner
|
||||
echo -ne "${_omb_term_normal}"
|
||||
}
|
||||
batch_chmod() {
|
||||
echo -ne "${_omb_term_bold_navy}Applying 0755 permission for all directories..."
|
||||
(find . -type d -print0 | xargs -0 chmod 0755) &
|
||||
spinner
|
||||
echo -ne "${_omb_term_normal}"
|
||||
|
||||
echo -ne "${_omb_term_bold_navy}Applying 0644 permission for all files..."
|
||||
(find . -type f -print0 | xargs -0 chmod 0644) &
|
||||
spinner
|
||||
echo -ne "${_omb_term_normal}"
|
||||
}
|
||||
|
||||
# usage: disk usage per directory, in Mac OS X and Linux
|
||||
# -------------------------------------------------------------------
|
||||
usage () {
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
if [ -n "$1" ]; then
|
||||
du -hd 1 "$1"
|
||||
else
|
||||
du -hd 1
|
||||
fi
|
||||
elif [ "$(uname)" = "Linux" ]; then
|
||||
if [ -n "$1" ]; then
|
||||
du -h --max-depth=1 "$1"
|
||||
else
|
||||
du -h --max-depth=1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
usage () {
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
if [ -n "$1" ]; then
|
||||
du -hd 1 "$1"
|
||||
else
|
||||
du -hd 1
|
||||
fi
|
||||
elif [ "$(uname)" = "Linux" ]; then
|
||||
if [ -n "$1" ]; then
|
||||
du -h --max-depth=1 "$1"
|
||||
else
|
||||
du -h --max-depth=1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# pickfrom: picks random line from file
|
||||
# -------------------------------------------------------------------
|
||||
pickfrom () {
|
||||
local file=$1
|
||||
[ -z "$file" ] && reference "$FUNCNAME" && return
|
||||
length=$(wc -l < "$file")
|
||||
n=$( ($RANDOM \* "$length" / 32768 + 1))
|
||||
head -n "$n" "$file" | tail -1
|
||||
}
|
||||
pickfrom () {
|
||||
local file=$1
|
||||
[ -z "$file" ] && reference "$FUNCNAME" && return
|
||||
length=$(wc -l < "$file")
|
||||
n=$( ($RANDOM \* "$length" / 32768 + 1))
|
||||
head -n "$n" "$file" | tail -1
|
||||
}
|
||||
|
||||
# passgen: generates random password from dictionary words
|
||||
# Note default length of generated password is 4, you can pass it to the command
|
||||
@ -290,12 +290,12 @@ bigfind() {
|
||||
# shellcheck disable=SC2005
|
||||
# shellcheck disable=SC2034
|
||||
# shellcheck disable=SC2086
|
||||
passgen () {
|
||||
local i pass length=${1:-4}
|
||||
pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done))
|
||||
echo "With spaces (easier to memorize): $pass"
|
||||
echo "Without (use this as the password): $(echo $pass | tr -d ' ')"
|
||||
}
|
||||
passgen () {
|
||||
local i pass length=${1:-4}
|
||||
pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done))
|
||||
echo "With spaces (easier to memorize): $pass"
|
||||
echo "Without (use this as the password): $(echo $pass | tr -d ' ')"
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------
|
||||
@ -311,7 +311,7 @@ httpHeaders () { /usr/bin/curl -I -L "$@" ; } # httpHeaders: Gr
|
||||
|
||||
# httpDebug: Download a web page and show info on what took time
|
||||
# -------------------------------------------------------------------
|
||||
httpDebug () { /usr/bin/curl "$@" -o /dev/null -w "dns: %{time_namelookup} connect: %{time_connect} pretransfer: %{time_pretransfer} starttransfer: %{time_starttransfer} total: %{time_total}\\n" ; }
|
||||
httpDebug () { /usr/bin/curl "$@" -o /dev/null -w "dns: %{time_namelookup} connect: %{time_connect} pretransfer: %{time_pretransfer} starttransfer: %{time_starttransfer} total: %{time_total}\\n" ; }
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user