forked from deanrather/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotfiles.sh
executable file
·140 lines (118 loc) · 3.54 KB
/
dotfiles.sh
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
#!/bin/bash
# dotfiles.sh
# Configures the terminal, prompt, etc.
## CONFIGURATION ##
# Configure History to automatically save
export HISTCONTROL=ignoredups:erasedups # no duplicate entries
export HISTSIZE=100000 # big big history
export HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it
# Save and reload the history after each command finishes
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
# Configure history to save with timestamp
export HISTTIMEFORMAT="%Y-%m-%d %T "
# Generating Help
# This saves a list of defined functions to the variable
# It will be compared to a list we'll make futher down,
# so we can know which functions were defined.
[[ "$original_function_list" ]] || original_function_list=$(compgen -A function)
# Source any scripts in the ~/dotfiles-autoload directory
[ -d ~/dotfiles-autoload ] || mkdir ~/dotfiles-autoload
if [ "$(ls -A ~/dotfiles-autoload)" ]
then
for script in ~/dotfiles-autoload/*
do
source "$script"
done
fi
unset script
# Get list of other functions defined
[[ "$other_function_list" ]] ||
other_function_list=$(grep -Fxv -f \
<(echo -e "$original_function_list\n$misc_function_list") \
<(compgen -A function))
# Displays list of functions defined by ~/dotfiles/dotfiles.sh
_dotfiles_help()
{
local help=''
help+="$(describe_functions "$dotfiles_function_list" "dotfiles functions:")"
help+="$(describe_functions "$misc_function_list" "Misc functions:")"
help+="$(describe_functions "$other_function_list" "Other functions:")"
less -qf <(echo "$help")
}
_dotfiles_version()
{
local git_dir
git_dir=~/dotfiles/.git
git --git-dir="$git_dir" log -1 --pretty="%ci (%cr) - %s"
}
_dotfiles_debug()
{
bash -e ~/dotfiles/dotfiles.sh
}
# Reloads bash
_dotfiles_reload()
{
# clear
# unset other_function_list
# unset original_function_list
# unset misc_function_list
# unset dotfiles_function_list
source ~/.profile
}
# Updates dotfiles from github
_dotfiles_pull()
{
cd ~/dotfiles
git pull
dotfiles reload
cd -
}
# push dotfiles to github
_dotfiles_push()
{
cd ~/dotfiles
git commit -am "updated with dotfiles push"
git push
git status
cd -
}
_dotfiles_hotkey()
{
echo 'hotkey pressed' >> /tmp/dotfiles-hotkey.log
}
# Provides various helpful functions
dotfiles()
{
# If no member function passed, show help
if [ -z "$1" ]
then
dotfiles help
return 0
fi
local member_function="$(printf "_%s_%s" "$FUNCNAME" "$1")"
if [ "$(type -t "$member_function")" = "function" ]
then
$member_function
else
echo -en "Undefined function: $member_function\nsee:\n\tdotfiles help\n\n"
return 1
fi
}
# Enable running dotfiles functions by either:
# - dotfiles <function name>
# - _dotfiles_<function name>
# - . ~/.dotfiles <function name>
[ -n "$1" ] && dotfiles $1
# Get list of dotfiles functions
[[ "$dotfiles_function_list" ]] ||
dotfiles_function_list=$(grep -Fxv -f \
<(echo -e "$original_function_list\n$misc_function_list\n$other_function_list") \
<(compgen -A function))
# Provide autocompletions
dotfiles_function_names="$(echo $dotfiles_function_list | sed 's/_dotfiles_//g')"
dotfiles_function_names="$(echo $dotfiles_function_names | sed 's/ dotfiles//g')"
complete -W "$dotfiles_function_names" dotfiles
# Ensure SSH agent is running
# eval $(ssh-agent) > /dev/null 2>&1 &
# ssh-add ~/.ssh/*