Browse Source

add POSIX-shell compliance and precompiled headers automation

master
RinRi 2 years ago
parent
commit
e177160738
8 changed files with 44 additions and 22 deletions
  1. +2
    -0
      .config.d/.nl
  2. +6
    -4
      .config.d/color.sh
  3. +7
    -0
      .gitignore
  4. +5
    -0
      Makefile
  5. +14
    -13
      README.md
  6. +2
    -0
      create.sh
  7. +2
    -0
      run.sh
  8. +6
    -5
      setup.sh

+ 2
- 0
.config.d/.nl View File

@@ -1,2 +1,4 @@
#!/bin/sh

./$1
echo

+ 6
- 4
.config.d/color.sh View File

@@ -1,7 +1,9 @@
echo -en "" ## red
#!/bin/sh

echo -n "" ## red
eval $* | while read line; do
echo -en "" ## blue
echo -n "" ## blue
echo $line
echo -en "" ## red
echo -n "" ## red
done
echo -en "" ## reset color
echo -n "" ## reset color

+ 7
- 0
.gitignore View File

@@ -0,0 +1,7 @@
*.cpp
*.out
*.h
*.hpp
bits
./.config.d/*.cpp
./.config.d/cursorpos

+ 5
- 0
Makefile View File

@@ -6,5 +6,10 @@ all: $(patsubst %.cpp, %.out, $(wildcard *.cpp))
%.out: %.cpp Makefile
$(CXX) $(CXXFLAGS) $< -o $@

cpstd:
mkdir bits
cp /usr/include/c++/*/*/bits/stdc++.h bits
$(CXX) $(CXXFLAGS) bits/stdc++.h

clean:
rm *.out

+ 14
- 13
README.md View File

@@ -1,3 +1,10 @@
Cpsrc is a tool to automate and enhance competitive programmer's experience. It works well with neovim and C++. You can also modify it to use the editor and programming language of your choice.

Cpsrc offers several features:
- Automatic template
- Fast and easy compilation (using Makefile and precompiled headers)
- Colored input/output

# Installation

Clone the repository and make setup.sh executable and run it:
@@ -9,37 +16,31 @@ chmod +x setup.sh
./setup.sh
```

First, write a template which will be used to create new files. Enter the number of the starting line. That is it!
Write a template that will be used to create new .cpp files. Enter the number of the starting line.

# Usage

To create a new .cpp file, run create.sh with filename argument:
To create a new .cpp file, run create.sh with a filename as an argument:

```shell
./create.sh 1234a
```

It will create 1234a.cpp and open neovim. Enter either type 1234a.cpp and 1234a.
It will create 1234a.cpp and open neovim. Enter either 1234a.cpp or 1234a.

To compile and run file, use run.sh with filename(or problem name) as an argument:
To compile and run the file, use run.sh with the filename (or problem name, e.g., 1234a) as an argument:

```shell
./run.sh 1234a.cpp
```

To compile faster, precompile needed header files in the directory.
To compile extremely fast, precompile needed header files in the directory. To precompile bits/stdc++.h use `make`:

```shell
# copy libraries
mkdir bits
cd bits
cp /usr/include/c++/10.2.0/x86_64-pc-linux-gnu/bits/stdc++.h .

# compile them and use the same c++ standard as in Makefile
g++ -g -std=c++14 stdc++.h
make cpstd
```

Don't forget to use double quotes in the template. GCC uses the local precompiled library first. If there is no local library, it uses system's one.
If it didn't work, you should do it manually by copying a header file in the directory and compiling it with the same flags used in the Makefile. Don't forget to use double quotes in your template. With double quotes, GCC uses a local header first.

```c++
#include "bits/stdc++.h"


+ 2
- 0
create.sh View File

@@ -1,2 +1,4 @@
#!/bin/sh

cp .config.d/template.cpp ${1%.*}.cpp
nvim -s .config.d/cursorpos ${1%.*}.cpp

+ 2
- 0
run.sh View File

@@ -1,3 +1,5 @@
#!/bin/sh

make
echo "Compiled..."
./.config.d/color.sh .config.d/.nl ./"${1%.*}.out"


+ 6
- 5
setup.sh View File

@@ -1,13 +1,14 @@
#!/bin/sh

# template
read -n 1 -r -s -p $'Press any key to create template file...\n'
read -p 'Press Enter to create a template...' line
nvim .config.d/template.cpp

# start line
read -p $'Enter starting line of cursor:\n' line
((line=line-1))
# starting line
read -p "Enter the starting line: " line
echo "$line"gg > .config.d/cursorpos

# make all executable
# make everything executable
chmod +x create.sh
chmod +x run.sh
chmod +x .config.d/color.sh


Loading…
Cancel
Save