Skip to content

Instantly share code, notes, and snippets.

@stormvirux
Forked from aliparsai/comment-cleanup.sh
Last active May 30, 2022 12:03
Show Gist options
  • Select an option

  • Save stormvirux/1ae3dc19a116964f03abdf6ee0934738 to your computer and use it in GitHub Desktop.

Select an option

Save stormvirux/1ae3dc19a116964f03abdf6ee0934738 to your computer and use it in GitHub Desktop.

Revisions

  1. stormvirux revised this gist May 30, 2022. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions comment-cleanup.sh
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@

    ## Clean-up Comments from Latex Source Files
    ## Copyright (c) 2020 Ali Parsai [email protected]
    ## Copyright (c) 2021 Thaha Mohammed
    ##
    ## Dependencies: sponge from moreutils, latexpand, sed, cat, mv, date, cp
    ##
    @@ -42,12 +43,12 @@ check_dependency latexpand



    dt=$(date '+%d%m%Y-%H%M%S')
    for src in "$@"
    do
    backup="${src}.bak.${dt}"
    cp -v "$src" "$backup"
    done
    #dt=$(date '+%d%m%Y-%H%M%S')
    #for src in "$@"
    # do
    # backup="${src}.bak.${dt}"
    # cp -v "$src" "$backup"
    # done

    for src in "$@"
    do
  2. @aliparsai aliparsai revised this gist Jan 23, 2020. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions comment-cleanup.sh
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ check_dependency () {
    if type $1 ; then
    echo "==> $1 found."
    else
    date "==> $1 not found. Exitting."
    echo "==> $1 not found. Exitting."
    exit 1
    fi
    }
    @@ -41,7 +41,8 @@ check_dependency sponge
    check_dependency latexpand


    dt=$(date '+%d/%m/%Y %H:%M:%S')

    dt=$(date '+%d%m%Y-%H%M%S')
    for src in "$@"
    do
    backup="${src}.bak.${dt}"
  3. @aliparsai aliparsai revised this gist Jan 23, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions comment-cleanup.sh
    Original file line number Diff line number Diff line change
    @@ -45,6 +45,7 @@ dt=$(date '+%d/%m/%Y %H:%M:%S')
    for src in "$@"
    do
    backup="${src}.bak.${dt}"
    cp -v "$src" "$backup"
    done

    for src in "$@"
  4. @aliparsai aliparsai created this gist Jan 23, 2020.
    58 changes: 58 additions & 0 deletions comment-cleanup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    #!/bin/bash

    ## Clean-up Comments from Latex Source Files
    ## Copyright (c) 2020 Ali Parsai [email protected]
    ##
    ## Dependencies: sponge from moreutils, latexpand, sed, cat, mv, date, cp
    ##
    ## CAUTION: Use version control or backup your files before using this script.
    ##
    ## How to use: comment-cleanup.sh TEX_FILE(S)
    ##
    ## This program is free software: you can redistribute it and/or modify
    ## it under the terms of the GNU General Public License as published by
    ## the Free Software Foundation, either version 3 of the License, or
    ## (at your option) any later version.
    ##
    ## This program is distributed in the hope that it will be useful,
    ## but WITHOUT ANY WARRANTY; without even the implied warranty of
    ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    ## GNU General Public License for more details.
    ##
    ## You should have received a copy of the GNU General Public License
    ## along with this program. If not, see <https://www.gnu.org/licenses/>.
    ##

    check_dependency () {
    if type $1 ; then
    echo "==> $1 found."
    else
    date "==> $1 not found. Exitting."
    exit 1
    fi
    }

    check_dependency mv
    check_dependency cp
    check_dependency date
    check_dependency cat
    check_dependency sed
    check_dependency sponge
    check_dependency latexpand


    dt=$(date '+%d/%m/%Y %H:%M:%S')
    for src in "$@"
    do
    backup="${src}.bak.${dt}"
    done

    for src in "$@"
    do
    dest="${src/.tex/-stripped.tex}"
    latexpand --empty-comments --keep-includes "$src" > "$dest"
    sed -i '/^\s*%/d' "$dest"
    cat -s "$dest" | sponge "$dest"
    mv "$dest" "$src"
    echo "==> Processed: $src"
    done