Skip to content

Instantly share code, notes, and snippets.

@gpressutto5
Last active March 8, 2020 20:28
Show Gist options
  • Save gpressutto5/26a45ea8787a607ad6757bba5bc38cf8 to your computer and use it in GitHub Desktop.
Save gpressutto5/26a45ea8787a607ad6757bba5bc38cf8 to your computer and use it in GitHub Desktop.
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$HOME/.composer/vendor/bin:/usr/local/sbin:$PATH
PROMPT_TITLE='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
export PROMPT_COMMAND="${PROMPT_COMMAND} ${PROMPT_TITLE}; "
# Fix https://github.com/robbyrussell/oh-my-zsh/issues/6835#issuecomment-390
ZSH_DISABLE_COMPFIX=true
# Set CLICOLOR if you want Ansi Colors in iTerm2
export CLICOLOR=1
# Set colors to match iTerm2 Terminal Colors
export TERM=xterm-256color
# Path to your oh-my-zsh installation.
export ZSH=/Users/guilherme/.oh-my-zsh
# Theme
ZSH_THEME="pressutto"
# Plugins
plugins=(git laravel5 zsh-autosuggestions yarn)
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# Language
export LANG=pt_BR.UTF-8
# ssh
export SSH_KEY_PATH="~/.ssh/rsa_id"
# go workplace
export GOPATH="$HOME/code/go"
export PATH=$GOPATH/bin:$PATH
# lolcommits
export LOLCOMMITS_DIR=$HOME/Pictures/lolcommits
export LOLCOMMITS_DELAY=3
export LOLCOMMITS_STEALTH=true
export LOLCOMMITS_FORK=true
# Aliases
alias git=hub
alias gs="git status -s"
alias p=phpunit
alias pf="phpunit --filter"
alias bend="composer test-all && composer style-check && gpsup"
alias cleangit="git branch --merged master | grep -v \"\\* master\" | xargs -n 1 git branch -d"
alias glo="git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all"
alias gds='git diff --stat'
alias m="php /Users/guilherme/Sites/magento2/bin/magento"
alias wttr="curl wttr.in"
alias dump="php artisan dump-server"
alias vscode="code"
# Functions
function selfie() (
local SELFIE_ARCHIVE_PATH="$HOME/Documents/selfies"
mkdir -p "${SELFIE_ARCHIVE_PATH}"
local filepath
filepath="${SELFIE_ARCHIVE_PATH}/$(date +%Y%m%d-%H%M%S).jpg"
function guarantee_bin_installed() {
local bin=$1
local install_command=$2
if ! [ -x "$(command -v "${bin}")" ]; then
echo "${bin} is not installed. Trying to install it..."
if eval "${install_command}"; then
echo "Successfully installed ${bin}."
else
echo "Couldn't install ${bin}."
exit 1
fi
fi
}
function print_help() {
cat <<HEREDOC
Simple function that takes a selfie and saves it.
Usage:
selfie [<options>]
Options:
-h --help Show this screen.
-c --copy Copy the taken selfie to clipboard.
HEREDOC
exit 0
}
function take_and_save_selfie() {
guarantee_bin_installed "imagesnap" "brew install imagesnap"
imagesnap "$filepath" -w 2 -q
}
function copy_selfie() {
local install_script
install_script=$( cat << 'HEREDOC'
trap 'rm -f "/tmp/impbcopy.m"' 0
trap 'exit $?' 1 2 3 15
curl -s https://gist.githubusercontent.com/gpressutto5/da3f193dfea33005a584eaf7f8c847c0/raw/74a52624e34ac47f885d5d8877cdc4158003a482/impbcopy.m >/tmp/impbcopy.m
gcc -Wall -g -O3 -ObjC -framework Foundation -framework AppKit -o /usr/local/bin/impbcopy /tmp/impbcopy.m
HEREDOC
)
guarantee_bin_installed "impbcopy" "${install_script}"
impbcopy "$filepath"
}
if [ "${1}" = "-h" ] || [ "${1}" = "--help" ]
then
print_help
exit 0
fi
take_and_save_selfie
if [ "${1}" = "-c" ] || [ "${1}" = "--copy" ]
then
copy_selfie
fi
exit 0
)
#!/usr/bin/env python
# coding=UTF-8
import math
import subprocess
p = subprocess.Popen(["ioreg", "-rc", "AppleSmartBattery"],
stdout=subprocess.PIPE)
output = p.communicate()[0]
o_max = [l for l in output.splitlines() if 'MaxCapacity' in l][0]
o_cur = [l for l in output.splitlines() if 'CurrentCapacity' in l][0]
b_max = float(o_max.rpartition('=')[-1].strip())
b_cur = float(o_cur.rpartition('=')[-1].strip())
charge = b_cur / b_max if b_max != 0 else 1
charge_threshold = int(math.ceil(10 * charge))
# Output
total_slots, slots = 10, []
filled = int(math.ceil(charge_threshold * (total_slots / 10.0))) * u'▸'
empty = (total_slots - len(filled)) * u'▹'
out = (filled + empty).encode('utf-8')
import sys
green = '\033[01;32m'
red = '\033[01;31m'
yello = '\033[01;33m'
reset = '\033[00m'
color_out = (
green if len(filled) > 6
else yello if len(filled) > 4
else red
)
out = color_out + out + reset
sys.stdout.write(out)
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
function get_pwd() {
print -D $PWD
}
function battery_charge() {
if [ -e ~/battery_indicator.py ]
then
echo `python ~/battery_indicator.py`
else
echo ''
fi
}
function put_spacing() {
local git=$(git_prompt_info)
if [ ${#git} != 0 ]; then
((git=${#git} - 10))
else
git=0
fi
local bat=$(battery_charge)
if [ ${#bat} != 0 ]; then
((bat = ${#bat} - 18))
else
bat=0
fi
local termwidth
(( termwidth = ${COLUMNS} - 6 - ${#$(get_pwd)} - ${bat} - ${git} ))
local spacing=""
for i in {1..$termwidth}; do
spacing="${spacing} "
done
echo $spacing
}
function precmd() {
print -rP '
$fg[yellow]$(get_pwd)$(put_spacing)$(git_prompt_info) $(battery_charge)'
}
local ret_status="%(?:👉🏻 :✋🏻 )"
PROMPT='%{$reset_color%}${ret_status}'
ZSH_THEME_GIT_PROMPT_PREFIX="[git:"
ZSH_THEME_GIT_PROMPT_SUFFIX="]$reset_color"
ZSH_THEME_GIT_PROMPT_DIRTY="$fg[red]+"
ZSH_THEME_GIT_PROMPT_CLEAN="$fg[green]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment