forked from colonelpanic/dotfiles
Make functions.sh style consistent
This commit is contained in:
parent
8866d80e75
commit
fe59575676
1
dotfiles/emacs.d/.gitignore
vendored
1
dotfiles/emacs.d/.gitignore
vendored
@ -47,3 +47,4 @@ uber.el
|
||||
url
|
||||
var
|
||||
xkcd
|
||||
.lsp-session-v1
|
||||
|
@ -27,7 +27,7 @@ function exists_in_path_var {
|
||||
[[ ":$path_contents:" == *":$1:"* ]]
|
||||
}
|
||||
|
||||
function split_into_vars () {
|
||||
function split_into_vars {
|
||||
local string IFS
|
||||
|
||||
string="$1"
|
||||
@ -38,7 +38,7 @@ $string
|
||||
EOF
|
||||
}
|
||||
|
||||
function echo_split () {
|
||||
function echo_split {
|
||||
local IFS
|
||||
IFS="$2" read -rA -- arr <<EOF
|
||||
$1
|
||||
@ -48,7 +48,7 @@ EOF
|
||||
done
|
||||
}
|
||||
|
||||
function shell_contains () {
|
||||
function shell_contains {
|
||||
local e
|
||||
for e in "${@:2}"; do
|
||||
[[ "$1" == *"$e"* ]] && return 0
|
||||
@ -56,21 +56,14 @@ function shell_contains () {
|
||||
return 1
|
||||
}
|
||||
|
||||
function dotfiles_directory() {
|
||||
function dotfiles_directory {
|
||||
echo $(dirname `readlink -f ~/.zshrc | xargs dirname`)
|
||||
}
|
||||
|
||||
function go2dotfiles() {
|
||||
function go2dotfiles {
|
||||
cd $(dotfiles_directory)
|
||||
}
|
||||
|
||||
function update_dotfiles() {
|
||||
local old_pwd=$(pwd)
|
||||
go2dotfiles
|
||||
git ffo
|
||||
cd $old_pwd
|
||||
}
|
||||
|
||||
function current_shell() {
|
||||
which "$(ps -p $$ | tail -1 | awk '{print $NF}' | sed 's/\-//')"
|
||||
}
|
||||
@ -79,24 +72,11 @@ function is_zsh() {
|
||||
[ ! -z ${ZSH_VERSION+x} ]
|
||||
}
|
||||
|
||||
function git_diff_add() {
|
||||
function git_diff_add {
|
||||
git status --porcelain | awk '{print $2}' | xargs -I filename sh -c "git du filename && git add filename"
|
||||
}
|
||||
|
||||
function confirm() {
|
||||
# call with a prompt string or use a default
|
||||
read -r -p "$1" response
|
||||
case $response in
|
||||
[yY][eE][sS]|[yY])
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function get_cols() {
|
||||
function get_cols {
|
||||
FS=' '
|
||||
OPTIND=1
|
||||
while getopts "F:" OPTCHAR; do
|
||||
@ -114,16 +94,8 @@ function filter_by_column_value {
|
||||
awk '$'"$1"' == '"$2"' { print $0 }'
|
||||
}
|
||||
|
||||
function find_all_ssh_agent_sockets() {
|
||||
find /tmp -type s -name agent.\* 2> /dev/null | grep '/tmp/ssh-.*/agent.*'
|
||||
}
|
||||
|
||||
function set_ssh_agent_socket() {
|
||||
export SSH_AUTH_SOCK=$(find_all_ssh_agent_sockets | tail -n 1 | awk -F: '{print $1}')
|
||||
}
|
||||
|
||||
# Determine size of a file or total size of a directory
|
||||
function fs() {
|
||||
function fs {
|
||||
if du -b /dev/null > /dev/null 2>&1; then
|
||||
local arg=-sbh
|
||||
else
|
||||
@ -137,7 +109,7 @@ function fs() {
|
||||
}
|
||||
|
||||
# Start an HTTP server from a directory, optionally specifying the port
|
||||
function server() {
|
||||
function server {
|
||||
local port="${1:-8000}"
|
||||
sleep 1 && open "http://localhost:${port}/" &
|
||||
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
|
||||
@ -146,7 +118,7 @@ function server() {
|
||||
}
|
||||
|
||||
# All the dig info
|
||||
function digga() {
|
||||
function digga {
|
||||
dig +nocmd "$1" any +multiline +noall +answer
|
||||
}
|
||||
|
||||
@ -261,59 +233,14 @@ function git_prune_all_history_involving {
|
||||
--prune-empty --tag-name-filter cat -- --all
|
||||
}
|
||||
|
||||
function set_osx_hostname() {
|
||||
local new_hostname="${1-imalison}"
|
||||
sudo scutil --set ComputerName $new_hostname
|
||||
sudo scutil --set HostName $new_hostname
|
||||
sudo scutil --set LocalHostName $new_hostname
|
||||
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string $new_hostname
|
||||
}
|
||||
|
||||
function pip_package_location() {
|
||||
pip show $1 | grep Location | get_cols 2
|
||||
}
|
||||
|
||||
function set_modifier_keys_on_all_keyboards() {
|
||||
for vendor_product_id in $(get_keyboard_vendor_id_product_id_pairs | tr " " "-"); do
|
||||
set_modifier_keys_for_vendor_product_id $vendor_product_id 0 2; echo $vendor_product_id;
|
||||
done;
|
||||
}
|
||||
|
||||
function get_keyboard_vendor_id_product_id_pairs() {
|
||||
ioreg -n IOHIDKeyboard -r | grep -e 'class IOHIDKeyboard' -e VendorID\" -e Product | gawk 'BEGIN { RS = "class IOHIDKeyboard" } match($0, /VendorID. = ([0-9]*)/, arr) { printf arr[1]} match($0, /ProductID. = ([0-9]*)/, arr) { printf " %s\n", arr[1]} '
|
||||
}
|
||||
|
||||
function git_config_string() {
|
||||
git config -f $1 --list | xargs -I kv printf '-c \"%s\" ' kv
|
||||
}
|
||||
|
||||
function talk_dirty_to_me() {
|
||||
python - <<EOF
|
||||
from random import randrange
|
||||
import re
|
||||
import urllib
|
||||
|
||||
def talk_dirty_to_me():
|
||||
socket = urllib.urlopen("http://www.youporn.com/random/video/")
|
||||
htmlSource = socket.read()
|
||||
socket.close()
|
||||
result = re.findall('<p class="message">((?:.|\\n)*?)</p>', htmlSource)
|
||||
if len(result):
|
||||
print result[randrange(len(result))]
|
||||
else:
|
||||
talk_dirty_to_me()
|
||||
|
||||
talk_dirty_to_me()
|
||||
EOF
|
||||
}
|
||||
|
||||
function dirty_talk() {
|
||||
while :
|
||||
do
|
||||
talk_dirty_to_me | tee >(cat) | say
|
||||
done
|
||||
}
|
||||
|
||||
function track_modified {
|
||||
local timestamp_file="/tmp/__track_modified_timestamp__"
|
||||
touch $timestamp_file
|
||||
@ -328,15 +255,6 @@ function python_module_path {
|
||||
python -c "import os, $1; print(os.path.dirname($1.__file__))"
|
||||
}
|
||||
|
||||
function mu4e_directory {
|
||||
if is_osx; then
|
||||
echo "$(brew --prefix mu)/share/emacs/site-lisp/mu4e"
|
||||
else
|
||||
# TODO: make this cleaner.
|
||||
echo "/usr/share/emacs/site-lisp/mu4e"
|
||||
fi
|
||||
}
|
||||
|
||||
function timestamp {
|
||||
date +%s
|
||||
}
|
||||
@ -349,106 +267,18 @@ function parse_timestamp2 {
|
||||
date -d "@$(echo $1 | cut -c -10)" -Iseconds
|
||||
}
|
||||
|
||||
function clear_path {
|
||||
export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin"
|
||||
unset PATH_HELPER_RAN
|
||||
unset ENVIRONMENT_SETUP_DONE
|
||||
}
|
||||
|
||||
function refresh_config {
|
||||
clear_path
|
||||
source ~/.zshenv
|
||||
source ~/.zshrc
|
||||
}
|
||||
|
||||
function file_ends_with_newline {
|
||||
[[ $(tail -c1 "$1" | wc -l) -gt 0 ]]
|
||||
}
|
||||
|
||||
function add_authorized_key_to_host {
|
||||
local command='test -e ~/.ssh/authorized_keys && [[ $(tail -c1 ~/.ssh/authorized_keys | wc -l) -gt 0 ]] || echo "\n" >> ~/.ssh/authorized_keys;'"echo $(cat ~/.ssh/id_rsa.pub) >> ~/.ssh/authorized_keys"
|
||||
echo "Running:"
|
||||
echo $command
|
||||
ssh $1 "$command"
|
||||
}
|
||||
|
||||
function add_ssh_key {
|
||||
[[ $(tail -c1 ~/.ssh/authorized_keys | wc -l) -gt 0 ]] || echo "\n" >> ~/.ssh/authorized_keys;
|
||||
echo $1 >> ~/.ssh/authorized_keys;
|
||||
}
|
||||
|
||||
function git_free_ssh_rsync {
|
||||
echo $1
|
||||
rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress --exclude=".git/" $(readlink -f "$1") $2:$1
|
||||
}
|
||||
|
||||
function project_sync {
|
||||
git_free_ssh_rsync '~/Projects/'"$1"'/' $2
|
||||
}
|
||||
|
||||
function android_sdk_directory {
|
||||
if is_osx; then
|
||||
brew --prefix android-sdk
|
||||
fi
|
||||
}
|
||||
|
||||
function pkill_zsh {
|
||||
ps aux | grep "$1" | grep -v grep | get_cols 2 | xargs kill -9
|
||||
}
|
||||
|
||||
|
||||
function find_by_size {
|
||||
find . -type f -size +$1
|
||||
}
|
||||
|
||||
function get_git_project_name {
|
||||
# "$(basename $(git rev-parse --show-toplevel))"
|
||||
basename $(git remotes | get_cols 2 | head -n 1)
|
||||
}
|
||||
|
||||
function add_github_remote {
|
||||
local project_name="$(get_git_project_name)"
|
||||
git remote add "$1" "git@github.com:$1/$project_name"
|
||||
}
|
||||
|
||||
function define_jump_alias_with_completion {
|
||||
eval "alias $1='jump_cd $2'"
|
||||
compdef "_files -g '$2/*'" $1
|
||||
}
|
||||
|
||||
function jump_cd {
|
||||
if [[ $2 =~ ^/ ]]; then
|
||||
cd $2
|
||||
else
|
||||
cd $1
|
||||
cd $2
|
||||
fi
|
||||
}
|
||||
|
||||
function source_if_exists {
|
||||
test -r "$1" && source "$1"
|
||||
}
|
||||
|
||||
function python_module_exists {
|
||||
python_module_path $@ 1>/dev/null 2>/dev/null
|
||||
}
|
||||
|
||||
function set_default_prompt {
|
||||
python_module_exists powerline && set_powerline_prompt || set_my_prompt
|
||||
}
|
||||
|
||||
function edit_script {
|
||||
$EDITOR "$(which $1)"
|
||||
}
|
||||
|
||||
function in_git_directory {
|
||||
[ -d .git ]
|
||||
}
|
||||
|
||||
function process_running {
|
||||
[[ ! -z "$(pgrep $@)" ]]
|
||||
}
|
||||
|
||||
function which_readlink {
|
||||
readlink -f "$(which $1)"
|
||||
}
|
||||
@ -460,9 +290,6 @@ function localip {
|
||||
;;
|
||||
'Linux')
|
||||
ip -4 addr | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v 127.0.0.1 | head -n 1
|
||||
# This was a nicer solution, but it returns ipv6 addresses on
|
||||
# machines that have them:
|
||||
# hostname --ip-address
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@ -480,11 +307,3 @@ function all_after_char {
|
||||
echo ${line##*$1}
|
||||
done;
|
||||
}
|
||||
|
||||
function find_local_ssh_hosts {
|
||||
nmap -p 22 --open -sV 10.0.0.0/24 | grep -Eo "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
|
||||
}
|
||||
|
||||
function rwhich {
|
||||
readlink -f $(which $1)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user