-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash-it
More file actions
114 lines (95 loc) · 3.76 KB
/
bash-it
File metadata and controls
114 lines (95 loc) · 3.76 KB
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
#!/bin/bash
VERSION=0.0.18
echo "Installing bit..."
mkdir -p ~/.bit_{exports,aliases,functions}
if [ -e ~/.bash_profile ] ; then
if [ -w ~/.bash_profile ] ; then
sed -i '/#BASH-IT/,/#\/BASH-IT/d' ~/.bash_profile
else
echo "Warning: .bash_profile is not writeable"
fi
fi
cat << EOF > ~/.bit_exports/version
export BIT_VERSION=$VERSION
EOF
cat << 'EOF' >> ~/.bash_profile
#BASH-IT
for f in ~/.bit_{exports,aliases,functions}/*; do source $f; done
#/BASH-IT
EOF
cat << 'EOF' > ~/.bit_exports/path_home_bin
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
EOF
cat << 'EOF' > ~/.bit_exports/prompt
export PS1=$'\[\033[30;47m\] `date +%H:%M:%S` \[\033[37;41m\]\xee\x82\xb0\[\033[37m\] \u@\h \[\033[31;40m\]\xee\x82\xb0\[\033[37m\] `pwd | sed -r "s#"$HOME"#~#g; s#^/##g; s#/# \xee\x82\xb1 #g"` \[\033[0;30m\]$([[ -n $(git branch 2> /dev/null) ]] && (BRACOL=$([[ -z $(parse_git_dirty) ]] && echo 2 || echo 3) && echo -e "\[\033[30;"$((40+BRACOL))"m\]\xee\x82\xb0 \xee\x82\xa0 $(parse_git_branch) \[\033[0;"$((30+BRACOL))"m\]"))\xee\x82\xb0\n\[\033[30;47m\] $ \[\033[0;37m\]\xee\x82\xb0 '
export PS2=$'\[\033[30;47m\] \[\033[0;37m\]\xee\x82\xb0 '
EOF
cat << 'EOF' > ~/.bit_exports/editor
if command -v vim > /dev/null ; then
export EDITOR=vim
elif command -v vi > /dev/null ; then
export EDITOR=vi
fi
EOF
cat << 'EOF' > ~/.bit_exports/systemd_editor
export SYSTEMD_EDITOR=vim
EOF
cat << 'EOF' > ~/.bit_aliases/ls
# Detect which `ls` flavor is in use
if ls --color > /dev/null 2>&1; then # GNU `ls`
colorflag="--color"
else # OS X `ls`
colorflag="-G"
fi
# List all files colorized in long format
alias ll='ls -lh'
# List all files colorized in long format, including dot files
alias la="ls -lha"
# List only directories
alias lsd='ls -l | grep "^d"'
# Always use color output for `ls`
alias ls="command ls ${colorflag}"
#export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
export LS_COLORS='di=00;34:ln=00;35:so=00;32:pi=01;33:ex=00;31:bd=00;34'
EOF
cat << 'EOF' > ~/.bit_functions/parse_git_dirty
function parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != *"working directory clean"* ]] && echo "*"
}
EOF
cat << 'EOF' > ~/.bit_functions/parse_git_branch
function parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/^* //g"
}
EOF
cat << 'EOF' > ~/.bit_functions/bit
function bit() {
case "$1" in
pw)
env LC_CTYPE=C tr -dc "a-zA-Z0-9-_\$\?" < /dev/urandom | head -c $2
echo ""
;;
update)
curl -L https://raw.github.com/gotofoo/bit/master/bash-it?$(date +"%s") | bash
source ~/.bash_profile
;;
*)
echo "BIT version $BIT_VERSION"
echo ""
echo "Use the following command to install BIT:"
echo " curl -L https://raw.github.com/gotofoo/bit/master/bash-it | bash"
echo ""
echo "Usage:"
echo " bit <command> [args...]"
echo ""
echo "Commands:"
echo " pw <length> - generates a random password"
echo " update - updates BIT to the latest version"
return 1
esac
}
EOF
echo "Installed bit $VERSION"