-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathforge
More file actions
executable file
·44 lines (34 loc) · 772 Bytes
/
forge
File metadata and controls
executable file
·44 lines (34 loc) · 772 Bytes
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
#!/usr/bin/env bash
set -o nounset -o pipefail
shopt -s extglob
if [[ $0 != *reforge ]]; then
IFS= read -r d < <(
find ~/tmp/forge -mindepth 1 -maxdepth 1 -type d -printf '%T@\t%p\n' |
sort -rn | cut -f2
)
fi
if [[ -v d && -d $d ]]; then
if [[ ${1:-} == --dir ]]; then
printf '%s\n' "$d"
else
vim "$d/main.cpp" +'set aw' +'cd %:h'
fi
exit
fi
mkdir -p ~/tmp/forge || exit
until d=~/tmp/forge/$(qn) && mkdir "$d"; do :; done
cat > "$d/main.cpp" <<'EOF'
#include <iostream>
using namespace std;
int main() {
}
EOF
cat > "$d/makefile" <<'EOF'
main: main.cpp
g++ -Wall -Wextra -pedantic $< -o $@
EOF
if [[ ${1:-} == --dir ]]; then
printf '%s\n' "$d"
else
vim "$d/main.cpp" +'set aw' +'cd %:h' +6 +'startinsert!'
fi