-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc
143 lines (117 loc) · 3.96 KB
/
bashrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
## export
export EDITOR=vim
# export WIRELESS_INTERFACE=`iw dev | sed '2q;d' | cut -d' ' -f2`
export HISTSIZE=100000
export HISTFILESIZE=100000
## source all files in the 'aliases' directory
for f in ~/.aliases/*; do source $f; done
## git aliases
source ~/.aliases/git
## curlable webapps
alias bvg='ruby ~/programming/scripts/bus_stop_info.rb'
## system aliases
alias grep='grep --color=auto'
alias feh='feh -d --scale-down'
alias ls='ls --color=auto'
# display active user processes
alias pp='ps -u $(whoami) -o ucmd,pid,%cpu,%mem'
alias system_update='sudo pacman -S archlinux-keyring && sudo pacman -Syu && sudo pacman -Rsunc $(pacman -Qdtq)'
alias unmount_all='devmon --unmount-all'
alias zzz='systemctl suspend'
## helpers
alias last_update=get_last_update
alias diskusage=determine_disk_usage
alias murder=murder
alias for_files_in=for_files_in
alias import_photos=import_photos
alias hlogs=tail_heroku_logs
### shortcuts
alias r='bundle exec ruby -r "./spec/spec_helper" -Ilib:spec:test'
alias rspec="LD_LIBRARY_PATH=$HOME/libs rspec"
alias rake='bundle exec rake'
alias telemimi='telegram-desktop & exit'
alias torrent=open_torrent_client
alias prod_console='connect_to_console prod'
alias staging_console='connect_to_console staging'
# takes one of "stage" or "prod"
function connect_to_console {
if pacman -Qi aws-vault > /dev/null ; then
InstanceID=$(aws-vault exec $1 -- aws ec2 describe-instances --filters "Name=tag:Name,Values=console-instance" --query 'Reservations[*].Instances[*].[InstanceId]' --output text);
aws-vault exec $1 -- aws ssm start-session --target $InstanceID
else
echo "AWS console connections are not available on this machine"
fi
}
# Get relative wireless signal strength
function WIP-get_signal_strength {
local signal=`iwconfig $WIRELESS_INTERFACE |grep Signal`
local formatted_signal=$($signal | cut -d'=' -f2 | cut -d'/' -f1)
echo $formatted_signal 70 | awk '{print $1 / $2}'
}
function write_planetary_rulers {
local rulers=`ruby ~/programming/scripts/planetary_hour.rb`
echo $rulers > $HOME/i3test
}
# Get date of last full system update
function get_last_update {
awk '/pacman -Syu/ {print $1" "$2}' /var/log/pacman.log | tail -n 1 | cut -c 2-17
}
# Loop through files in directory and do something
function for_files_in {
if [ $# -lt 2 ]; then
echo "Usage: for_files_in <directory> <command to preform on each file>"
fi
for file in $1/*; do $2 $file; done
}
# Send a kill -9 signal to PID
function murder {
if [[ "$1" != "" ]]; then
local process_name="cat /proc/1444/status | sed -n '1p' | awk '{print $NF}'"
kill -9 $1
echo "Murdered process '$process_name' with PID $1"
else
echo "Who shall I kill?" 1>&2
fi
}
# Determine disk useage through a modified `du` command
function determine_disk_usage {
if [[ "$1" != "" ]]; then
DIR="$1"
else
DIR="/*"
fi
sudo du -h --max-depth=1 $DIR | sort -h
}
# Stream tail of heroku logs to console with default options
# tail_heroku_logs <appname>
function tail_heroku_logs {
heroku logs --force-colors --tail -a $1
}
function open_torrent_client {
local status=`mullvad status | sed 's/ .*//'`
if [[ $status == "Connected" ]]; then
fragments
else
echo "You are not connected to a VPN. Please connect and try again."
fi
}
## Determine the current git-branch if in a git directory
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\<\1\> /'
}
# Name screen tabs whatever the current directory is
function set_screen_title {
if [[ "$TERM" == screen* ]]; then
local TITLE="$PWD"
case $TITLE in
$HOME) TITLE="~";;
$HOME/*) TITLE="$(basename $TITLE)";;
esac
printf '\ek%s\e\\' "$TITLE"
fi
}
## Export the prompt
export PROMPT_COMMAND=set_screen_title
PS1='\[\033[0;37m\][\[\e[0;37m\]\[\e[0;37m\]\[\e[0;37m\]\[\e[0;37m\]\w\[\e[0;37m\]]\[\e[0;37m\]\[\033[1;31m\]$(parse_git_branch)\[\033[1;31m\]\[\e[0;37m\]'