forked from dluc/bashrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc.functions
73 lines (59 loc) · 2.06 KB
/
.bashrc.functions
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
function my_ip() {
MY_IP=$(/sbin/ifconfig eth0 | awk "/inet/ { print $2 } " | sed -e s/addr://)
MY_ISP=$(/sbin/ifconfig eth0 | awk "/P-t-P/ { print $3 } " | sed -e s/P-t-P://)
}
function ii() {
echo -e "\nYou are logged on ${RED}$HOST"
echo -e "\nAdditionnal information:$NC " ; uname -a
echo -e "\n${RED}Users logged on:$NC " ; w -h
echo -e "\n${RED}Current date :$NC " ; date
echo -e "\n${RED}Machine stats :$NC " ; uptime
echo -e "\n${RED}Memory stats :$NC " ; free
my_ip 2>&- ;
echo -e "\n${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"}
echo -e "\n${RED}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"}
echo
}
function my_ps() {
ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ;
}
function pp() {
my_ps f | awk '!/awk/ && $0~var' var=${1:-".*"} ;
}
# branch name plus dirtiness
function parse_git_branch {
if git update-index -q --refresh 2>/dev/null; git diff-index --quiet --cached HEAD --ignore-submodules -- 2>/dev/null && git diff-files --quiet --ignore-submodules 2>/dev/null
then dirty=""
else
dirty="*"
fi
_branch=$(git symbolic-ref HEAD 2>/dev/null)
_branch=${_branch#refs/heads/} # apparently faster than sed
branch="" # need this to clear it when we leave a repo
if [[ -n $_branch ]]; then
branch=" [${_branch}${dirty}]"
fi
echo $branch
}
# copy ssh public key to remote server
function sshcopyid {
KEY="$HOME/.ssh/id_dsa.pub"
if [ ! -f $KEY ];then
echo "private key not found at $KEY"
echo '* please create it with "ssh-keygen -t dsa"'
echo "* to login to the remote host without a password, don't give the key you create with ssh-keygen a password"
return
fi
if [ -z $1 ];then
echo "Please specify [email protected] as the first switch to this script"
return
fi
echo "Putting your public key on $1... "
cat $KEY | ssh -q $1 "mkdir ~/.ssh 2>/dev/null; chmod 700 ~/.ssh; cat - >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys"
echo "done!"
}
#function setmyproxy {
# export http_proxy=http://127.0.0.1:80
# export https_proxy=http://127.0.0.1:80
# export ftp_proxy=http://127.0.0.1:80
#}