Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/atapas/add-copyright

This is a Script to Automate adding the Copyright text to one or more source files Recursively.
https://github.com/atapas/add-copyright

add-copyright automation bash bash-script copyright hacktoberfest license script

Last synced: about 2 months ago
JSON representation

This is a Script to Automate adding the Copyright text to one or more source files Recursively.

Awesome Lists containing this project

README

        

# add-copyright

[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fatapas%2Fadd-copyright.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fatapas%2Fadd-copyright?ref=badge_shield)

This is a **Script to Automate** adding the Copyright text to one or more source files **Recursively**. The Copyright texts get added to the top of the source file. Ice on the Cake is, it doesn't duplicate the copyright text if it is added already!

Note: The same tool can be used to add any such text blocks like, License, File level Comments etc.

Here is an example of JavaScript(.js) file.

```js

/*
© Copyright 2020 tapasadhikary.com or one of its affiliates.
* Some Sample Copyright Text Line
* Some Sample Copyright Text Line
* Some Sample Copyright Text Line
* Some Sample Copyright Text Line
* Some Sample Copyright Text Line
* Some Sample Copyright Text Line
*/

const test = () => {
console.log('test');
}

test();
```

# To Run this on your Source Code

- Clone the project. This project comes with a script file called `addcopyright.sh` and few test files to test out things before you feel comfortable to try it on your source code.
- Browse to the folder where you have cloned the project.
- Change directory to `add-copyright` folder.
- Open a shell or Gitbash or any unix command supported prompt.
- Execute this command:
```bash
export COPYRIGHTLEN=`wc -l copyright.txt | cut -f1 -d ' '`
```
The above command will set some variable value that will be used by the `addcopyright.sh` script.
- Execute the following command to add the copyright/license text from the `copyright.txt` to your source code:
```bash
find -type d -name "" -prune -o -name "*.js" -print0 | xargs -0 ./addcopyright.sh
```
Where the `` is the path of your source code.
Where the `` is the directory to exclude if it exists under `` for updating the Copyright information.

# Usage
Make sure you have given the execute permission to the `addcopyright.sh` script file. You can provide the permission using following command:

```bash
chmod +x addcopyright.sh
```
If your user is not having root privileges, add your $USER to 'roots' group using command :
```bash
useradd -m -G root $USER
```
Alternatively:

Insert 'sudo' when executing the run command. For example:
```bash
sudo find -type d -name "" -prune -o -name "*.js" -print0 | sudo xargs -0 ./addcopyright.sh
```
## Running it on Source Code without any Exclusions
For running the tool on the Source code without excluding any folders, use this command:

```bash
find -name "*.js" -print0 | xargs -0 ./addcopyright.sh
```
- For current directory use `.`(dot)
- If your source code is in `/home/atapas/code` directory, use the above command as,
```bash
find -name "*.js" -print0 | xargs -0 ./addcopyright.sh
```

## Running it on Source Code with Exclusions(Say, node_modules)
For Running the tool on the Source Code by excluding the folder of your desire(say, node_modules for nodeJs based applications), use this command:

```bash
find /opt/atapas/code -type d -name "node_modules" -prune -o -name "*.js" -print0 | xargs -0 ./addcopyright.sh
```
### Excluding multiple directories(Say, node_modules and test)
If your source code is in `/home/atapas/code` and want to exclude `node_modules` and `test` directories, use the above command as,

```bash
find /opt/atapas/code -type d -name "node_modules" -prune -o -type d -name "test" -prune -o -name "*.js" -print0 | xargs -0 ./addcopyright.sh
```

## Change the file Types
To Change the file type, just replace the `*.js` with any other extentions like, `*.java`, `*.cpp` etc.

# Limitations

- This tool can only be run from a Linux Bash Shell. For running it from windows use any bash shell like [GitBash](https://git-scm.com/download/win).
- This tool can be made use for different language files like javascript, java, c, c++, html, shell-script etc. However the content of the `copyright.txt` should be changed according to the mult-line comment format. For example,

For Javascript(.js) or Java(.java) files this is the format:

```js

/*
This is a comment
*/
```

For HTML(.htm or .html) file the format should be,

```html


```

## Credit

The soution was found as part of this discussion on the StackOverflow and keep improving thereafter!

- https://stackoverflow.com/questions/151677/tool-for-adding-license-headers-to-source-files

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



IAMLEGION98

⚠️

Tapas Adhikary

💻

Pradeep Repaka

💻

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fatapas%2Fadd-copyright.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fatapas%2Fadd-copyright?ref=badge_large)