Git Product home page Git Product logo

add-copyright's Introduction

add-copyright

All Contributors FOSSA Status

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.

/*
 © 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:
     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:
     find <SOURCE_CODE_DIRECTIRY> -type d -name "<EXCLUDE_DIRECTORY>" -prune -o -name "*.js" -print0 | xargs -0 ./addcopyright.sh
    Where the <SOURCE_CODE_DIRECTIRY> is the path of your source code. Where the <EXCLUDE_DIRECTORY> is the directory to exclude if it exists under <SOURCE_CODE_DIRECTIRY> 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:

chmod +x addcopyright.sh

If your user is not having root privileges, add your $USER to 'roots' group using command :

useradd -m -G root $USER

Alternatively:
Insert 'sudo' when executing the run command. For example:

 sudo find <SOURCE_CODE_DIRECTIRY> -type d -name "<EXCLUDE_DIRECTORY>" -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:

find <SOURCE_CODE_DIRECTIRY>  -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,
      find <SOURCE_CODE_DIRECTIRY>  -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:

 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,

   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.

  • 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:

        
     /*
      This is a comment
     */

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

        
    <!-- 
       This is a HTML Comment
    -->

Credit

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

Contributors ✨

Thanks goes to these wonderful people (emoji key):


IAMLEGION98

⚠️

Tapas Adhikary

💻

Pradeep Repaka

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

License

FOSSA Status

add-copyright's People

Contributors

allcontributors[bot] avatar atapas avatar fossabot avatar iamlegion98 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.