Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/atapas/add-copyright
- Owner: atapas
- License: mit
- Created: 2020-04-17T04:29:21.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-27T21:49:43.000Z (almost 2 years ago)
- Last Synced: 2024-10-31T14:45:23.872Z (about 2 months ago)
- Topics: add-copyright, automation, bash, bash-script, copyright, hacktoberfest, license, script
- Language: JavaScript
- Homepage: https://blog.greenroots.info/add-copyright-or-license-text-to-the-source-files-recursively-ck93zodue042h7us1nur56u4f
- Size: 63.5 KB
- Stars: 82
- Watchers: 4
- Forks: 23
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
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
```
## CreditThe 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)