-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsource
executable file
·167 lines (143 loc) · 4.94 KB
/
source
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
###################################
# DUzun's dotfiles main source #
# @version 2.4.0 #
# @author Dumitru Uzun (DUzun.Me) #
###################################
# ------------------------------------------------------------------------------
if [ -n "$ZSH_NAME" ] || [ -n "$ZSH_VERSION" ]; then
_profile="${(%):-%N}"
elif [ -n "$BASH" ]; then
_profile=${BASH_SOURCE:-$0}
else
_profile=$(lsof -p $$ 2> /dev/null | grep "\b$$\b" | tail -1 | tr ' \t' '\n' | tail -1)
fi
# ------------------------------------------------------------------------------
if ! command -v realpath >/dev/null; then
_realpath() {
local _l _d
_l=$1
if [ -L "$_l" ]; then
_l=$(readlink "$_l") || return $?
# If symlink is relative:
if [ "${_l:0:1}" != "/" ]; then
_d=$(dirname "$1")
[ "$_d" = "." ] && _d=${PWD:-$(pwd)}
[ "$_d" != "." ] && [ -n "$_d" ] && _l="$_d/$_l"
fi
fi
echo "$_l"
[ -e "$_l" ]
}
_dotfiles=$(dirname "$(_realpath "$_profile")")
. "$_dotfiles/../src/realpath/.realpath"
fi
# ------------------------------------------------------------------------------
_profile=$(realpath "$_profile")
_dotfiles=$(dirname "$_profile")
# ------------------------------------------------------------------------------
. "$_dotfiles/.aliasrc"
# ------------------------------------------------------------------------------
# non-POSIX section bellow!
declare -l _os
declare -l _shell
_os=$(ostype)
_shell=$(shelltype)
_git_aliases_complete=()
_aliases_complete=(
dfh du1 du0
dcs dcsb dcsu dcsd
ccur
)
# ------------------------------------------------------------------------------
. "$_dotfiles/.aliasrc.dotfiles"
# ------------------------------------------------------------------------------
_init_commands() {
[ -d "$1" ] || return 1
local _file _cmd _path
for _file in "$1"/*.sh; do
_cmd="${_file##*/}"
_path=$(command -v "${_cmd%.*}" 2>/dev/null) && . "$_file" "$_path"
done
}
_init_commands "$_dotfiles/command"
# ------------------------------------------------------------------------------
[ -n "$_shell" ] && [ -f "$_dotfiles/.aliasrc.$_shell" ] && . "$_dotfiles/.aliasrc.$_shell"
[ -n "$_os" ] && [ -f "$_dotfiles/.aliasrc.$_os" ] && . "$_dotfiles/.aliasrc.$_os"
[ -f ~/.extend.aliasrc ] && . ~/.extend.aliasrc
# ------------------------------------------------------------------------------
alias .cd="cd '$_dotfiles/..'"
alias .source=". '$_dotfiles/source'"
alias .update="( cd '$(dirname "$_dotfiles")' && git pull --rebase --recurse-submodules) && .source"
alias .open_git="open \"\$(dotfiles_url)\""
# ------------------------------------------------------------------------------
# Set the prompt and shell behaviour
. "$_dotfiles/prompt"
# echo "_aliases_complete (${#_aliases_complete[@]}):" "${_aliases_complete[@]}"
# echo "_git_aliases_complete (${#_git_aliases_complete[@]}):" "${_git_aliases_complete[@]}"
# ------------------------------------------------------------------------------
# Custom .profile
[ -f ~/.extend.source ] && . ~/.extend.source
# ------------------------------------------------------------------------------
if [ ! -f "$EDITOR_PATH" ]; then
EDITOR_PATH=$(command -v vim)
EDITOR_ARGS=
fi
# ------------------------------------------------------------------------------
if [ -z "$EDITOR" ] && [ -n "$EDITOR_PATH" ] && [ -x "$EDITOR_PATH" ]; then
export EDITOR="$EDITOR_PATH $EDITOR_ARGS"
fi
# ------------------------------------------------------------------------------
if [[ $- = *i* ]]; then
if [ -z "$NVM_DIR" ]; then
export NVM_DIR=~/.nvm
if [ -s "$NVM_DIR/nvm.sh" ]; then
# This loads nvm
. "$NVM_DIR/nvm.sh"
# When there is no node.js in the environment,
# load it with nvm
command -v node >/dev/null || nvm use node
fi
fi
if [ -z "$VOLTA_HOME" ]; then
export VOLTA_HOME=~/.volta
if [ -d "$VOLTA_HOME/bin" ]; then
add_path "$VOLTA_HOME/bin"
fi
fi
# If direnv hooked and .envrc exists in current dirrectory,
# don't add local composer and npm to the path. Let dotenv handle this dir.
if command -v _direnv_hook > /dev/null && [ -e "$PWD/.envrc" ]; then
composerbin -g
else
composerbin
npmbin
fi
fi
# ------------------------------------------------------------------------------
if [ $# -ne 0 ] && \
{ [ -z "${BASH_SOURCE[*]}" ] || [ "${BASH_SOURCE[0]}" == "$0" ]; } && \
[ "$(basename "$0")" != "Xsession" ];
then
_cmd="$1"
shift
case "$_cmd" in
init)
echo 'init'
init_dotfiles "$@"
exit $?
;;
init_git)
init_git "$@"
exit $?
;;
update)
.update
exit $?
;;
*)
echo_error "Unknown command '$_cmd'"
exit 1
;;
esac
fi