-
Notifications
You must be signed in to change notification settings - Fork 0
/
fortran_project
143 lines (121 loc) · 3.43 KB
/
fortran_project
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
#!/bin/bash
# ~/.local/bin/fortran_project.sh
#
VERSION="0.1"
MY_URL="https://raw.githubusercontent.com/ipqa-research/fortran-setup/main/fortran_project"
bold=$(tput bold)
normal=$(tput sgr0)
RED='\033[0;31m'
NC='\033[0m'
WORK_DIR="${FORTRAN_PROJECTS:-$HOME/codes}"
PFX=~/.local/bin
[ -d "$WORK_DIR" ] || mkdir -p "$WORK_DIR"
update_script() {
echo "updating..."
tmpfile=$(mktemp)
script="$(curl -s $MY_URL)"
echo "$script" > "$tmpfile"
chmod +x "$tmpfile"
exec mv "$tmpfile" "$PFX/fortran_project" && echo "done."
}
write_gitignore() {
echo "build" > .gitignore
echo "*.mod" >> .gitignore
echo "doc/ford_site" >> .gitignore
}
write_ford_file() {
mkdir -p doc/page
mkdir -p doc/media
echo "---
project: '<Project name>'
summary: '<Project description>'
project_github: '<Project github page>'
author: '<Main Author>'
author_description: '<Description of author>'
email: '<author email>'
github: '<author github>'
src_dir: src
exclude_dir: test doc example
output_dir: doc/ford_site
preprocessor: gfortran -E
display: public
protected
private
source: false
proc_internals: true
sort: permission-alpha
docmark_alt: !>
docmark: !
predocmark_alt: *
print_creation_date: true
creation_date: %Y-%m-%d %H:%M %z
md_extensions: markdown.extensions.toc
markdown.extensions.smarty
graph: false
license: MPL
page_dir: doc/page
media_dir: doc/media
---
[TOC]
{!README.md!}
" > ford.md
}
h="fortran_project <new|list|work|update|docs>
Manage your Fortran based projects locally with fpm and vscode.
USAGE:
- fortran_project ${bold}new${normal} <project_name>
Create a new project.
The default folder will be at ~/codes, but it can be set up with
the environment variable FORTRAN_PROJECTS.
If the directory doesn't exist, it will be created.
The project is generated with \`fpm\` and, besides the general setting,
includes a Ford documentation tempalte, a .gitignore file and
some vscode settings.
- fortran_project ${bold}list${normal}
List all the existing Fortran projects.
- fortran_project ${bold}work${normal}
Open vscode on the selected project directory.
- fortran_project ${bold}update${normal}
Update the fortran_project script
- fortran_project ${bold}docs${normal}
Generate Ford documentation.
"
case $1 in
"new")
if [ -z "$2" ]; then
echo "ERROR!"
echo "Project name must be provided!"
exit 1
fi
cd "$WORK_DIR"
nombre="$2"
fpm new "$nombre" --app --src --example --test &&
cd "$nombre" &&
# Añade configuraciones generales de vscode al proyecto
git clone "https://github.com/ipqa-research/vscode-fortran.git" .vscode &&
write_gitignore &&
write_ford_file "$nombre"
;;
"list")
ls $WORK_DIR
;;
"work")
proj="$(ls $WORK_DIR | fzf)"
cd "$WORK_DIR/$proj"
[ "$proj" = "" ] || code "$WORK_DIR/$proj"
;;
"update")
update_script
;;
"docs")
ford ford.md
;;
*)
echo "$h"
script="$(curl --no-progress-meter $MY_URL)"
if [ "$script" != "$(cat $PFX/fortran_project)" ]; then
echo -e "${RED} There is a newer version of fortran_project on line, it should be updated ${NC}. Run:"
echo "fortran_project update"
fi
;;
esac