mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-13 03:01:32 +01:00
changed some files.
This commit is contained in:
parent
90c28b786a
commit
d6be37aa32
5 changed files with 252 additions and 14 deletions
38
custom/battery.py
Executable file
38
custom/battery.py
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python
|
||||
# coding=UTF-8
|
||||
|
||||
import math, 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
|
||||
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
|
||||
|
||||
color_green = '%{[32m%}'
|
||||
color_yellow = '%{[1;33m%}'
|
||||
color_red = '%{[31m%}'
|
||||
color_reset = '%{[00m%}'
|
||||
color_out = (
|
||||
color_green if len(filled) > 6
|
||||
else color_yellow if len(filled) > 4
|
||||
else color_red
|
||||
)
|
||||
|
||||
out = color_out + out + color_reset
|
||||
sys.stdout.write(out)
|
||||
|
|
@ -16,11 +16,32 @@ alias please='sudo'
|
|||
alias history='fc -l 1'
|
||||
|
||||
# List direcory contents
|
||||
alias lsa='ls -lah'
|
||||
alias l='ls -la'
|
||||
alias ll='ls -l'
|
||||
alias la='ls -lA'
|
||||
alias sl=ls # often screw this up
|
||||
alias ls='gls --color=tty -hF'
|
||||
alias ll='gls --color=tty -lhFa'
|
||||
alias l='gls --color=tty -lhF'
|
||||
alias ss='open -a /System/Library/Frameworks/ScreenSaver.framework//Versions/A/Resources/ScreenSaverEngine.app'
|
||||
alias node="ssh rever@andrewfree.com"
|
||||
alias irc="ssh -t root@andrewfree.com screen -r"
|
||||
alias gfr="git fetch && git rebase remotes/origin/master"
|
||||
|
||||
|
||||
alias afind='ack-grep -il'
|
||||
|
||||
# Open in textmate
|
||||
alias o='subl $1'
|
||||
alias zshconfig='subl ~/.zshrc'
|
||||
alias ohmyzsh='subl ~/.oh-my-zsh'
|
||||
alias ft='open -g /opt/local/bin/ft.app/' # Launch terminal window of top finder window
|
||||
alias oo='open .'
|
||||
alias rm='/opt/local/bin/MacRm'
|
||||
alias rrm='/bin/rm'
|
||||
alias bp='bpython-2.7'
|
||||
|
||||
|
||||
alias ipx="curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'"
|
||||
alias mnode="sshfs root@andrewfree.com:/ /Users/rever/nodessh/"
|
||||
alias mtech="echo vjW5zWfXLMBDxnj9gJ7F | sshfs andrew@69.194.130.58:/home/andrew/ /Users/rever/techssh/"
|
||||
alias audio_pause="sudo pkill -STOP coreaudiod"
|
||||
alias audio_play="sudo pkill -CONT coreaudiod"
|
||||
# defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" 40
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
function zsh_stats() {
|
||||
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20
|
||||
op=$(history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20 )
|
||||
echo "$op"
|
||||
}
|
||||
|
||||
function uninstall_oh_my_zsh() {
|
||||
|
|
@ -15,3 +16,111 @@ function take() {
|
|||
cd $1
|
||||
}
|
||||
|
||||
|
||||
per(){
|
||||
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);print}'
|
||||
}
|
||||
|
||||
flush(){
|
||||
#Script to unload and reload mDNS as it is a bit crappy
|
||||
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
|
||||
echo "mDNS unloaded"
|
||||
sleep 5
|
||||
sudo launchctl load /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
|
||||
echo "mDNS loaded"
|
||||
sleep 5
|
||||
echo "Hopefully you can get on with browsing again"
|
||||
}
|
||||
|
||||
|
||||
dt() {
|
||||
result=$(defaults read com.apple.finder CreateDesktop)
|
||||
if [[ "$result" == 1 ]]
|
||||
then
|
||||
defaults write com.apple.finder CreateDesktop 0
|
||||
echo Hide desktop
|
||||
fi
|
||||
|
||||
if [[ "$result" == 0 ]]
|
||||
then
|
||||
defaults write com.apple.finder CreateDesktop 1
|
||||
echo Show desktop
|
||||
|
||||
fi
|
||||
killall Finder
|
||||
}
|
||||
work(){
|
||||
echo 'vjW5zWfXLMBDxnj9gJ7F\n'
|
||||
ssh andrew@69.194.130.58
|
||||
}
|
||||
|
||||
|
||||
|
||||
vis() {
|
||||
|
||||
|
||||
# check if hidden files are visible and store result in a variable
|
||||
isVisible=$(defaults read com.apple.finder AppleShowAllFiles)
|
||||
if [ "$isVisible" = "FALSE" ]
|
||||
then
|
||||
echo Hidden Viewing On
|
||||
defaults write com.apple.finder AppleShowAllFiles TRUE
|
||||
else
|
||||
echo Hidden Videwing Off
|
||||
defaults write com.apple.finder AppleShowAllFiles FALSE
|
||||
fi
|
||||
# force changes by restarting Finder
|
||||
killall Finder
|
||||
}
|
||||
|
||||
dl(){
|
||||
python ~/Desktop/musicdl.py `pbpaste`
|
||||
}
|
||||
|
||||
webserv(){
|
||||
python -m SimpleHTTPServer
|
||||
}
|
||||
|
||||
lsext()
|
||||
{
|
||||
find \( ! -name . -prune \) -type f -iname '*.'${1}'' -exec ls $LS_OPTIONS -hF {} \; ;
|
||||
}
|
||||
|
||||
rpass() {
|
||||
cat /dev/urandom | LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= | head -c ${1:-12}
|
||||
}
|
||||
|
||||
genpass() {
|
||||
local l=$1
|
||||
[ "$l" == "" ] && l=8
|
||||
LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= < /dev/urandom | head -c ${l} | xargs
|
||||
}
|
||||
|
||||
downloads() {
|
||||
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent' |more
|
||||
}
|
||||
hide(){
|
||||
chflags hidden $1
|
||||
}
|
||||
unhide(){
|
||||
chflags nohidden $1
|
||||
}
|
||||
connected(){
|
||||
lsof -i | grep ESTABLISHED
|
||||
}
|
||||
look(){
|
||||
qlmanage -p "$1"
|
||||
}
|
||||
|
||||
|
||||
mach()
|
||||
{
|
||||
echo -e "\nMachine information:" ; uname -a
|
||||
echo -e "\nUsers logged on:" ; w -h
|
||||
echo -e "\nCurrent date :" ; date
|
||||
echo -e "\nMachine status :" ; uptime
|
||||
echo -e "\nFilesystem status :"; df -h
|
||||
echo -e "\nMemory status :" ; top -l 1 | grep ^PhysMem
|
||||
echo -e "\nIP Information: "; curl ifconfig.me
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
# ls colors
|
||||
autoload colors; colors;
|
||||
export LSCOLORS="Gxfxcxdxbxegedabagacad"
|
||||
#export LS_COLORS
|
||||
export LS_COLORS="Gxfxcxdxbxegedabagacad"
|
||||
export LS_OPTIONS="Gxfxcxdxbxegedabagacad"
|
||||
|
||||
# Enable ls colors
|
||||
if [ "$DISABLE_LS_COLORS" != "true" ]
|
||||
|
|
@ -10,9 +10,10 @@ then
|
|||
if [[ "$(uname -s)" == "NetBSD" ]]; then
|
||||
# On NetBSD, test if "gls" (GNU ls) is installed (this one supports colors);
|
||||
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
|
||||
gls --color -d . &>/dev/null 2>&1 && alias ls='gls --color=tty'
|
||||
gls --color -d . &>/dev/null 2>&1
|
||||
else
|
||||
ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G'
|
||||
alias lsc='ls -G'
|
||||
#ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G'
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@
|
|||
|
||||
CURRENT_BG='NONE'
|
||||
SEGMENT_SEPARATOR=''
|
||||
|
||||
SEG_2=''
|
||||
ip=`curl -s icanhazip.com`
|
||||
# Begin a segment
|
||||
# Takes two arguments, background and foreground. Both can be omitted,
|
||||
# rendering default background/foreground.
|
||||
|
|
@ -36,7 +37,7 @@ prompt_segment() {
|
|||
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
|
||||
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
|
||||
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
|
||||
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
|
||||
echo -n " %{$reset_color%}%{$fg[black]%}%{$bg`echo '\033[104;32m'`%}$SEGMENT_SEPARATOR%{$bg%F{$CURRENT_BG}%}%{$fg%} "
|
||||
else
|
||||
echo -n "%{$bg%}%{$fg%} "
|
||||
fi
|
||||
|
|
@ -63,9 +64,10 @@ prompt_context() {
|
|||
local user=`whoami`
|
||||
|
||||
if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
|
||||
prompt_segment black default "%(!.%{%F{yellow}%}.)$user@%m"
|
||||
prompt_segment black default "%{$fg[red]%}%(!.%{%F{yellow}%}.)%n%{$fg[white]%}@%{$fg[blue]%}`scutil --get ComputerName`%{$reset_color%}%{$fg[black]%}%{`echo '\033[42m'`%}$SEGMENT_SEPARATOR$ip"
|
||||
fi
|
||||
}
|
||||
# prompt_segment black default "%{$fg[red]%}%(!.%{%F{yellow}%}.)%n%{$reset_color%}@%{$fg[blue]%}%m%{$reset_color%}%{$fg[black]%}`echo '\033[106m'`$SEGMENT_SEPARATOR$ip%{$reset_color%}%"
|
||||
|
||||
# Git: branch/detached head, dirty status
|
||||
prompt_git() {
|
||||
|
|
@ -131,7 +133,7 @@ prompt_hg() {
|
|||
|
||||
# Dir: current working directory
|
||||
prompt_dir() {
|
||||
prompt_segment blue black '%~'
|
||||
prompt_segment blue white "%{`echo '\033[44;32m'`%} %~ "
|
||||
}
|
||||
|
||||
# Virtualenv: current working virtualenv
|
||||
|
|
@ -168,4 +170,71 @@ build_prompt() {
|
|||
prompt_end
|
||||
}
|
||||
|
||||
PROMPT='%{%f%b%k%}$(build_prompt) '
|
||||
|
||||
typeset -Ag FX FG BG
|
||||
|
||||
FX=(
|
||||
reset "%{[00m%}"
|
||||
bold "%{[01m%}" no-bold "%{[22m%}"
|
||||
italic "%{[03m%}" no-italic "%{[23m%}"
|
||||
underline "%{[04m%}" no-underline "%{[24m%}"
|
||||
blink "%{[05m%}" no-blink "%{[25m%}"
|
||||
reverse "%{[07m%}" no-reverse "%{[27m%}"
|
||||
)
|
||||
|
||||
for color in {000..255}; do
|
||||
FG[$color]="%{[38;5;${color}m%}"
|
||||
BG[$color]="%{[48;5;${color}m%}"
|
||||
done
|
||||
|
||||
# Show all 256 colors with color number
|
||||
function spectrum_ls() {
|
||||
for code in {000..255}; do
|
||||
print -P -- "zz $code: %F{$code}zzz"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
function prompt_char {
|
||||
git branch >/dev/null 2>/dev/null && echo '±' && return
|
||||
hg root >/dev/null 2>/dev/null && echo '☿' && return
|
||||
echo '%(!.!.➜)'
|
||||
}
|
||||
|
||||
|
||||
function parse_hg_dirty {
|
||||
if [[ -n $(hg status -mard . 2> /dev/null) ]]; then
|
||||
echo "$ZSH_THEME_HG_PROMPT_DIRTY"
|
||||
fi
|
||||
}
|
||||
|
||||
function get_RAM {
|
||||
top -l1 | grep "PhysMem"| awk '{print (int($6)/1024)}'
|
||||
}
|
||||
|
||||
|
||||
function get_load() {
|
||||
uptime | awk '{print $11}' | tr ',' ' '
|
||||
}
|
||||
|
||||
function battery_charge {
|
||||
echo `~/.oh-my-zsh/custom/battery.py` 2>/dev/null
|
||||
}
|
||||
|
||||
#case '~/*' in '~/' ) echo "yes";;
|
||||
# * ) echo "no";;
|
||||
#esac
|
||||
|
||||
function user_folder_check {
|
||||
string='/Users/rever';
|
||||
path=`pwd`;
|
||||
if [[ $path == *$string* ]]
|
||||
then
|
||||
echo "Local";
|
||||
else
|
||||
echo "External";
|
||||
fi
|
||||
}
|
||||
RPROMPT='%{$fg_bold[white]%}$(user_folder_check) %{$fg_bold[green]%}%t%{$reset_color%} $(battery_charge)'
|
||||
|
||||
PROMPT='%{%f%b%k%}$(build_prompt) '
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue