-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasics.sh
More file actions
executable file
·221 lines (193 loc) · 5.96 KB
/
basics.sh
File metadata and controls
executable file
·221 lines (193 loc) · 5.96 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#
# __ __ ____ ____ _ _
# | \/ | / ___| / ___|| |_ _ __ ___ | |__
# | |\/| || | \___ \| __| '__/ _ \| '_ \
# | | | || |___ _ ___) | |_| | | (_) | | | |
# |_| |_(_)____(_) |____/ \__|_| \___/|_| |_|
#
# basics shell file catch-all for BASH/ZSH
#
# M. C. Stroh (mstroh@nrao.edu)
#
#
# Aliases
alias rm='rm -i'
alias ssh='ssh -X'
alias cdirs='for file in *; do if [ -d "$file" ]; then tar -czf "${file}.tar.gz" "$file"; fi; done'
alias crdirs='for file in *; do if [ -d "$file" ]; then tar -czf "${file}.tar.gz" "$file" && rm -rf "$file" || rm -rf "${file}.tar.gz"; fi; done'
if [ ! -z ${ZSH_VERSION+x} ]; then
export MAMBA_SHELL="zsh"
else
export MAMBA_SHELL="bash"
fi
hostname=`hostname`
hostname_short=`hostname | cut -c1-2`
nm_node=false
if [ "$hostname" = "gygax" ]; then
nm_node=true
elif [ "$hostname_short" = "nm" ]; then
nm_node=true
fi
# General extraction function
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
else
for n in "$@"
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.cbr|*.rar) unrar x -ad ./"$n" ;;
*.gz) gunzip ./"$n" ;;
*.cbz|*.epub|*.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n" ;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*.cpio) cpio -id < ./"$n" ;;
*.cba|*.ace) unace x ./"$n" ;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
}
# root privileges
alias doas="doas --"
# navigation
function up {
local d=""
local limit="$1"
# Default to limit of 1
if [ -z "$limit" ] || [ "$limit" -le 0 ]; then
limit=1
fi
for ((i=1;i<=limit;i++)); do
d="../$d"
done
# perform cd. Show error if cd fails
if ! cd "$d"; then
echo "Couldn't go up $limit dirs.";
fi
}
function cr {
dir="$1"
if [ -d "$dir" ]; then
tar -czf "${dir}.tar.gz" "$dir" && rm -rf "$dir" || rm -f "${dir}.tar.gz";
fi
}
function decompress_pipeline {
rm -rf bandpass_plots
rm -rf data_plots
rm -rf corrected_plots
tar xzf bandpass_plots.tar.gz
tar xzf data_plots.tar.gz
tar xzf corrected_plots.tar.gz
}
###############################################################################
#
# Configure local mamba installation if it exists
#
# Reference $HOME, to work for local macOS and Linux installations
if [ -d "$HOME/lustre" ]; then
export SOFTWARE_HOME="$HOME/lustre/software/"
else
export SOFTWARE_HOME="$HOME/../data/"
fi
#export MAMBA_ROOT_PREFIX="$HOME/../data/miniforge3"
export MAMBA_ROOT_PREFIX="$SOFTWARE_HOME/miniforge3"
export MAMBA_EXE="$MAMBA_ROOT_PREFIX/bin/mamba"
__mamba_setup="$("$MAMBA_EXE" shell hook --shell $MAMBA_SHELL --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
__conda_setup="$('$MAMBA_ROOT_PREFIX/bin/conda' 'shell.$MAMBA_SHELL' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__mamba_setup"
eval "$__conda_setup"
else
alias mamba="$MAMBA_EXE" # Fallback on help from mamba activate
if [ -f "$MAMBA_ROOT_PREFIX/etc/profile.d/conda.sh" ]; then
. "$MAMBA_ROOT_PREFIX/etc/profile.d/conda.sh"
else
export PATH="$MAMBA_ROOT_PREFIX/bin:$PATH"
fi
fi
unset __mamba_setup
unset __conda_setup
#
###############################################################################
###############################################################################
#
# Alias for Emacs on macOS due to bug with keyboard input not moving to window
#
#if [ "$(uname)"=="Darwin" ]; then
# alias emacs="emacs -nw"
#fi
#
#
###############################################################################
###############################################################################
#
# Consolidated data bin directory for manual installations
#
if [ -d "${HOME}/../data/bin" ]; then
export PATH="${HOME}/../data/bin:${PATH}"
fi
#
###############################################################################
###############################################################################
#
# NRAO configuration
#
if [ $nm_node ]; then
. "${HOME}/dotfiles/nrao.sh"
fi
#
#
###############################################################################
###############################################################################
#
# FTOOLS/CALDB
#
if [ -d "${HOME}/../data/heasoft" ] && [ -f "${HOME}/../data/heasoft/headas-init.sh" ]; then
export HEADAS="${HOME}/../data/heasoft"
. "$HEADAS/headas-init.sh"
fi
if [ -d "${HOME}/../data/caldb" ] ; then
export CALDB="${HOME}/../data/caldb"
. "$CALDB/software/tools/caldbinit.sh"
fi
#
#
###############################################################################
###############################################################################
#
# pipx
#
if [ -d $HOME/.local/bin ]; then
export PATH="$PATH:$HOME/.local/bin"
fi
#
###############################################################################
###############################################################################
#
# Julia
#
if [ -d $HOME/.juliaup/bin ]; then
export PATH="$PATH:$HOME/.juliaup/bin"
fi
#
###############################################################################
# Force unmount
alias fumnt="sudo umount -l"