-
Notifications
You must be signed in to change notification settings - Fork 1
/
.bash_profile
106 lines (89 loc) · 2.87 KB
/
.bash_profile
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
# tmux quick alias
alias tmux-load="tmux a -t"
alias tmux-new="tmux new -s"
tm() {
if [ $# -eq 0 ]
then
session_name="local"
else
session_name="$1"
fi
session_found=$(tmux list-sessions | awk -v session_name="$session_name" -F: '$1 == session_name {print $1}' | wc -l)
if [ $session_found == 1 ]
then
tmux-load "$session_name"
else
tmux-new "$session_name"
fi
#echo "SESSION: $session_name : $session_found"
}
# Remote Mount
###############################################################################
rmount() {
# Local variable, should stay in this function
local ssh_name mount_folder
ssh_name="${1%%:*}" # Get the first parameter until :
# If the first parameter is only the ssh name
# - The mount folder is empty
# - Else, use the remaining value after the :
[[ ${1%:} == $ssh_name ]] && mount_folder='' || mount_folder=${1##*:}
# Get the ssh name in SSH config, if available
custom_folder=$(grep -i "host $ssh_name" -m1 ~/.ssh/config)
# If the ssh name is found in the SSH config
if [[ $custom_folder != '' ]]; then
# Create the folder (no error if existing)
mkdir -p ~/Mounts/$ssh_name > /dev/null
# If the SSH config file has a comment on the Host line
if [[ $( echo $custom_folder | cut -d "#" -f2 ) != "Host $ssh_name" ]]; then
mount_folder=$( echo $custom_folder | cut -d "#" -f2 )
fi
# If no mount folder is specified, use a default one
if [[ $mount_folder == "" ]]; then
mount_folder="public_html/"
fi
# If mount folder is empty
if ! [[ $(ls ~/Mounts/$ssh_name) ]]; then
sshfs -o reconnect $ssh_name:$mount_folder ~/Mounts/$ssh_name && echo "~/Mounts/$ssh_name:$mount_folder mounted!" || (sshfs -o reconnect $ssh_name: ~/Mounts/$ssh_name && echo "~/Mounts/$ssh_name mounted!")
fi
cd ~/Mounts/$ssh_name
else
echo "No entry found for $ssh_name"
return 1
fi
}
# Remove Unmount
###############################################################################
rumount() {
# Unmount all folders
if [[ $1 == "-a" ]]; then
# Get all folders
ls -1 ~/Mounts/|while read dir
do
# Unmount
[[ $(mount | grep "Mounts/$dir") ]] && fusermount -u ~/Mounts/$dir
# Delete if empty
[[ $(ls ~/Mounts/$dir) ]] || rm -d ~/Mounts/$dir
done
else
# Unmount
[[ $(mount | grep "Mounts/$1") ]] && fusermount -u ~/Mounts/$1
# Delete if empty
[[ $(ls ~/Mounts/$1) ]] || rm -d ~/Mounts/$1
fi
}
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
whois_expiration() {
whois $1 | grep -i expi
}
alias expi=whois_expiration
if [ -f ~/.bash_profile_local ]; then
. ~/.bash_profile_local
fi