Giter Site home page Giter Site logo

daniel-sc / bash-shell-to-bat-converter Goto Github PK

View Code? Open in Web Editor NEW
213.0 9.0 43.0 4.04 MB

Converter for bash shell scripts to windows batch files.

Home Page: https://daniel-sc.github.io/bash-shell-to-bat-converter

License: MIT License

TypeScript 82.66% JavaScript 5.66% HTML 4.94% Batchfile 2.60% Shell 2.84% SCSS 1.30%
bash-hacks bash batch-script conversion windows-batch converter

bash-shell-to-bat-converter's Introduction

Simple Bash script to Windows batch file converter

npm Coverage Status

Converts bash scripts (*.sh) to windows batch files (*.bat). This is not supposed to be a fully complete/correct tool, but rather a starting point when converting scripts. For simple scripts this might create correct results.

Try it online: https://daniel-sc.github.io/bash-shell-to-bat-converter/

Usage

npx bash-converter FILE_TO_CONVERT.sh

This creates FILE_TO_CONVERT.bat.

Contribute

PRs always welcome ;-)

bash-shell-to-bat-converter's People

Contributors

daniel-sc avatar david-a-wheeler avatar deltabravozulu avatar dependabot[bot] avatar monstermichl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bash-shell-to-bat-converter's Issues

Converted result is incorrect

Hello,

Did make a incremental backup file in BASH but it also has been needed in Windows.
I am trying to convert a bash file into a batch file but it returns many %UNDEFINED% values.
So much that I can't figure out the solution.

CodeExample


#BEFORE USING BASH YOU WILL NEED TO MODIFY THE FILE TO: sudo chmod +x dailybackup.sh

#DATE VARIABLES
day="dag-`date +%d`" 
month="maand-`date +%m`"

# GLOBE VARS
basedirectory="/home/private/Source"

#PATH VARIABLES (IT CAN BE DIFFERENT)
source="$basedirectory/maanden/$month"
daydest="$basedirectory/dagen"
tempdest="$basedirectory/temp"
tosyncfiles="$basedirectory/temp/tosync"
monthdest="$basedirectory/maanden/$month"

#DIRECTORY CHECK
if [ ! -d $monthdest ] ; then
 mkdir $monthdest;
fi

#INCREMENTAL BACKUP LOGIC
for file in $(find $source -printf "%P\n") ; do
    if [ -a $source/$file ] ; then
#CHECK MONTLY BACKUP VERSUS THE EGNYTE FOLDERS
        if [ $source/$file -nt $tempdest/$file ] ; then
        echo "Nieuwe bestanden ontdekt.... $source/$file Kopie wordt gemaakt $tempdest"
        cp -r $source/$file $tempdest/$file && cp -r $source/$file  $tosyncfiles
        fi
    else
    echo "Bestanden gekopieerd naar $tempdest"
    cp -r $source/$file $tempdest/$file
    fi
done

if [ "$(ls -A $tosyncfiles)" ] ; then
   cd $tosyncfiles
   
   #ZIP EVERYTHING IN TOSYNC
   zip -r $day .
   
   #MOVE THE ZIP TO THE DAYS DIRECTORY
   mv $tosyncfiles/$day.zip $daydest
   
   #REMOVE THE FOLDERS AND FILES IN TOSYNC FOLDER
   rm -rf $tosyncfiles/*
   cd $basedirectory
   
   echo "Dagelijkse backup gemaakt `date +%d-%m-%Y_%H:%M:%S`" >> "log.txt"

 else
   echo "Er zijn geen nieuwe bestanden ontdekt om te back-uppen `date +%d-%m-%Y_%H:%M:%S`" >> "$basedirectory/log.txt"
fi

Use mode "word-expansion" instead of "bash"

Maybe by using the more low-level mode "word-expansion" one could support cases that currently lead to parse errors (arrays, substitution, ..)

const ast = parse(script, {mode: 'word-expansion'});

Of course this would be a major rewrite..

npm tossing two errors on linux (one related to ELIFECYCLE and one related to script references)

2020-06-02T02_56_21_194Z-debug.log

When running "npm run tsc" it spits out the following:

> [email protected] tsc /home/dbz/github/bash-shell-to-bat-converter
> tsc

error TS6059: File '/home/dbz/github/bash-shell-to-bat-converter/ui/e2e/src/app.e2e-spec.ts' is not under 'rootDir' '/home/dbz/github/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/dbz/github/bash-shell-to-bat-converter/ui/e2e/src/app.po.ts' is not under 'rootDir' '/home/dbz/github/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/dbz/github/bash-shell-to-bat-converter/ui/src/app/app.component.spec.ts' is not under 'rootDir' '/home/dbz/github/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/dbz/github/bash-shell-to-bat-converter/ui/src/app/app.component.ts' is not under 'rootDir' '/home/dbz/github/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/dbz/github/bash-shell-to-bat-converter/ui/src/app/app.module.ts' is not under 'rootDir' '/home/dbz/github/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/dbz/github/bash-shell-to-bat-converter/ui/src/environments/environment.prod.ts' is not under 'rootDir' '/home/dbz/github/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/dbz/github/bash-shell-to-bat-converter/ui/src/environments/environment.ts' is not under 'rootDir' '/home/dbz/github/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/dbz/github/bash-shell-to-bat-converter/ui/src/main.ts' is not under 'rootDir' '/home/dbz/github/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/dbz/github/bash-shell-to-bat-converter/ui/src/polyfills.ts' is not under 'rootDir' '/home/dbz/github/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File '/home/dbz/github/bash-shell-to-bat-converter/ui/src/test.ts' is not under 'rootDir' '/home/dbz/github/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] tsc: `tsc`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] tsc script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/dbz/.npm/_logs/2020-06-02T02_56_21_194Z-debug.log

Cannot install - npm run tsc fails because 'rootDir' is expected to contain all source files

I haven't been able to get a local install running so I can make improvements.

Any suggestions?

I have node installed on a Windows system, and try to set it up both with and without Cygwin. It fails on npm run tsc.

Here's the output when trying to do this from Cygwin, after cloning it into $HOME:

 npm run tsc

> [email protected] tsc C:\cygwin64\home\dwheeler\bash-shell-to-bat-converter
> tsc

error TS6059: File 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/ui/e2e/src/app.e2e-spec.ts' is not under 'rootDir' 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/ui/e2e/src/app.po.ts' is not under 'rootDir' 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/ui/src/app/app.component.spec.ts' is not under 'rootDir' 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/ui/src/app/app.component.ts' is not under 'rootDir' 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/ui/src/app/app.module.ts' is not under 'rootDir' 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/ui/src/environments/environment.prod.ts' is not under 'rootDir' 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/ui/src/environments/environment.ts' is not under 'rootDir' 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/ui/src/main.ts' is not under 'rootDir' 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/ui/src/polyfills.ts' is not under 'rootDir' 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/ui/src/test.ts' is not under 'rootDir' 'C:/cygwin64/home/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] tsc: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] tsc script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\dwheeler\AppData\Roaming\npm-cache\_logs\2020-05-31T17_24_08_909Z-debug.log

Here's a similar failure when trying to do this exclusively from Windows:


> [email protected] tsc C:\Users\dwheeler\bash-shell-to-bat-converter
> tsc

error TS6059: File 'C:/Users/dwheeler/bash-shell-to-bat-converter/ui/e2e/src/app.e2e-spec.ts' is not under 'rootDir' 'C:/Users/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/Users/dwheeler/bash-shell-to-bat-converter/ui/e2e/src/app.po.ts' is not under 'rootDir' 'C:/Users/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/Users/dwheeler/bash-shell-to-bat-converter/ui/src/app/app.component.spec.ts' is not under 'rootDir' 'C:/Users/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/Users/dwheeler/bash-shell-to-bat-converter/ui/src/app/app.component.ts' is not under 'rootDir' 'C:/Users/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/Users/dwheeler/bash-shell-to-bat-converter/ui/src/app/app.module.ts' is not under 'rootDir' 'C:/Users/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/Users/dwheeler/bash-shell-to-bat-converter/ui/src/environments/environment.prod.ts' is not under 'rootDir' 'C:/Users/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/Users/dwheeler/bash-shell-to-bat-converter/ui/src/environments/environment.ts' is not under 'rootDir' 'C:/Users/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/Users/dwheeler/bash-shell-to-bat-converter/ui/src/main.ts' is not under 'rootDir' 'C:/Users/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/Users/dwheeler/bash-shell-to-bat-converter/ui/src/polyfills.ts' is not under 'rootDir' 'C:/Users/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/Users/dwheeler/bash-shell-to-bat-converter/ui/src/test.ts' is not under 'rootDir' 'C:/Users/dwheeler/bash-shell-to-bat-converter/src'. 'rootDir' is expected to contain all source files.

ReferenceError: window is not defined

`
git clone https://github.com/daniel-sc/bash-shell-to-bat-converter.git
Cloning into 'bash-shell-to-bat-converter'...
remote: Enumerating objects: 174, done.
remote: Counting objects: 100% (174/174), done.
remote: Compressing objects: 100% (137/137), done.
remote: Total 174 (delta 70), reused 123 (delta 34), pack-reused 0
Receiving objects: 100% (174/174), 529.01 KiB | 823.00 KiB/s, done.
Resolving deltas: 100% (70/70), done.

cd bash-shell-to-bat-converter

npm i
added 32 packages from 59 contributors and audited 32 packages in 13.766s
found 0 vulnerabilities

npm run tsc

[email protected] tsc F:\bash-shell-to-bat-converter
tsc

node lib/cli.js uasp.sh
..\lib\convert-bash.js:5
window.process = { env: { NODE_NEV: 'mock' } }; // patch for irrelevant node dependency of bash-parser
^

ReferenceError: window is not defined`

Windows 10 x64
nodejs v10.15.1

I've trying online version but it doesn't work....

Once one fixes the tsconfig.json file, npm throws an error about bash-parser

npm run tsc
2020-06-02T03_08_06_105Z-debug.log

> [email protected] tsc /home/dbz/github/bash-shell-to-bat-converter
> tsc

src/convert-bash.ts(3,19): error TS7016: Could not find a declaration file for module 'bash-parser'. '/home/dbz/github/bash-shell-to-bat-converter/node_modules/bash-parser/src/index.js' implicitly has an 'any' type.
  Try `npm install @types/bash-parser` if it exists or add a new declaration (.d.ts) file containing `declare module 'bash-parser';`
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] tsc: `tsc`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] tsc script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/dbz/.npm/_logs/2020-06-02T03_08_06_105Z-debug.log

npm install @types/bash-barser
2020-06-02T03_08_07_850Z-debug.log

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fbash-parser - Not found
npm ERR! 404 
npm ERR! 404  '@types/bash-parser@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/dbz/.npm/_logs/2020-06-02T03_08_07_850Z-debug.log

sqitch docker-sqitch.sh file

https://github.com/sqitchers/docker-sqitch/blob/main/docker-sqitch.sh

#!/usr/bin/env bash

# Determine which Docker image to run.
SQITCH_IMAGE=${SQITCH_IMAGE:=sqitch/sqitch:latest}

# Set up required pass-through variables.
user=${USER-$(whoami)}
passopt=(
    -e "SQITCH_ORIG_SYSUSER=$user"
    -e "SQITCH_ORIG_EMAIL=$user@$(hostname)"
    -e "TZ=$(date +%Z)" \
    -e "LESS=${LESS:--R}" \
)

# Handle OS-specific options.
case "$(uname -s)" in
    Linux*)
        passopt+=(-e "SQITCH_ORIG_FULLNAME=$(getent passwd $user | cut -d: -f5 | cut -d, -f1)")
        passopt+=(-u $(id -u ${user}):$(id -g ${user}))
        ;;
    Darwin*)
        passopt+=(-e "SQITCH_ORIG_FULLNAME=$(/usr/bin/id -P $user | awk -F '[:]' '{print $8}')")
        ;;
    MINGW*|CYGWIN*)
        passopt+=(-e "SQITCH_ORIG_FULLNAME=$(net user $user)")
        ;;
    *)
        echo "Unknown OS: $(uname -s)"
        exit 2
        ;;
esac

# Iterate over optional Sqitch and engine variables.
for var in \
    SQITCH_CONFIG SQITCH_USERNAME SQITCH_PASSWORD SQITCH_FULLNAME SQITCH_EMAIL SQITCH_TARGET \
    DBI_TRACE \
    PGUSER PGPASSWORD PGHOST PGHOSTADDR PGPORT PGDATABASE PGSERVICE PGOPTIONS PGSSLMODE PGREQUIRESSL PGSSLCOMPRESSION PGREQUIREPEER PGKRBSRVNAME PGKRBSRVNAME PGGSSLIB PGCONNECT_TIMEOUT PGCLIENTENCODING PGTARGETSESSIONATTRS \
    MYSQL_PWD MYSQL_HOST MYSQL_TCP_PORT \
    TNS_ADMIN TWO_TASK ORACLE_SID \
    ISC_USER ISC_PASSWORD \
    VSQL_HOST VSQL_PORT VSQL_USER VSQL_PASSWORD VSQL_SSLMODE \
    SNOWSQL_ACCOUNT SNOWSQL_USER SNOWSQL_PWD SNOWSQL_HOST SNOWSQL_PORT SNOWSQL_DATABASE SNOWSQL_REGION SNOWSQL_WAREHOUSE SNOWSQL_PRIVATE_KEY_PASSPHRASE
do
    if [ -n "${!var}" ]; then
       passopt+=(-e $var)
    fi
done

# Determine the name of the container home directory.
homedst=/home
if [ $(id -u ${user}) -eq 0 ]; then
    homedst=/root
fi
# Set HOME, since the user ID likely won't be the same as for the sqitch user.
passopt+=(-e "HOME=${homedst}")

# Run the container with the current and home directories mounted.
docker run -it --rm --network host \
    --mount "type=bind,src=$(pwd),dst=/repo" \
    --mount "type=bind,src=$HOME,dst=$homedst" \
    "${passopt[@]}" "$SQITCH_IMAGE" "$@"

throws error

parse error: Error: Parse error on line 8: Unexpected 'OPEN_PAREN'

my manual progress so far

@echo off & setlocal EnableDelayedExpansion
setlocal
REM # Determine which Docker image to run.
if "%SQITCH_IMAGE%"=="" (
    set SQITCH_IMAGE=sqitch/sqitch:latest
) 
echo %SQITCH_IMAGE%
REM set SQITCH_IMAGE=sqitch/sqitch:latest

REM # Set up required pass-through variables.
REM set user=whoami
FOR /F "tokens=*" %%g IN ('whoami') do (SET user=%%g)
set passopt= -e "SQITCH_ORIG_SYSUSER=%username%"
FOR /F "tokens=*" %%g IN ('hostname') do (SET machinehostname=%%g)
set passopt=%passopt% -e "SQITCH_ORIG_EMAIL=%username%@%machinehostname%"
FOR /F "tokens=*" %%g IN ('tzutil /g') do (SET TZ=%%g)
set passopt=%passopt% -e "TZ=%TZ%"
if "%LESS%"=="" (
    set LESS=--R
)
if "%LESS%"=="" (
set passopt=%passopt% -e "LESS=%LESS%"

echo %passopt% 

REM # Iterate over optional Sqitch and engine variables.
REM for var in \
REM     SQITCH_CONFIG SQITCH_USERNAME SQITCH_PASSWORD SQITCH_FULLNAME SQITCH_EMAIL SQITCH_TARGET \
REM     DBI_TRACE \
REM     PGUSER PGPASSWORD PGHOST PGHOSTADDR PGPORT PGDATABASE PGSERVICE PGOPTIONS PGSSLMODE PGREQUIRESSL PGSSLCOMPRESSION PGREQUIREPEER PGKRBSRVNAME PGKRBSRVNAME PGGSSLIB PGCONNECT_TIMEOUT PGCLIENTENCODING PGTARGETSESSIONATTRS \
REM     MYSQL_PWD MYSQL_HOST MYSQL_TCP_PORT \
REM     TNS_ADMIN TWO_TASK ORACLE_SID \
REM     ISC_USER ISC_PASSWORD \
REM     VSQL_HOST VSQL_PORT VSQL_USER VSQL_PASSWORD VSQL_SSLMODE \
REM     SNOWSQL_ACCOUNT SNOWSQL_USER SNOWSQL_PWD SNOWSQL_HOST SNOWSQL_PORT SNOWSQL_DATABASE SNOWSQL_REGION SNOWSQL_WAREHOUSE SNOWSQL_PRIVATE_KEY_PASSPHRASE
REM do
REM     if [ -n "${!var}" ]; then
REM        passopt+=(-e $var)
REM     fi
REM done

REM # Determine the name of the container home directory.
set homedst=/home
REM if [ $(id -u ${user}) -eq 0 ]; then
REM     homedst=/root
REM fi
REM # Set HOME, since the user ID likely won't be the same as for the sqitch user.
set passopt=%passopt% -e "HOME=%homedst%"

REM # Run the container with the current and home directories mounted.
docker run -it --rm --network host \
    --mount "type=bind,src=$(pwd),dst=/repo" \
    --mount "type=bind,src=%HOME%,dst=%homedst%" \
    "%passopt%" "%SQITCH_IMAGE%"

echo end
endlocal

Error when convert: Command substitution

node lib/cli.js uasp.sh (script can be found here: https://github.com/kennethrisa/uasp)

return:
D:\bash-shell-to-bat-converter\node_modules\bash-parser\src\index.js:52
throw new Error(err.stack || err.message);
^

Error: Parse error on line 34: Unexpected 'OPEN_PAREN'
at Object.parse [as default] (D:\bash-shell-to-bat-converter\node_modul
es\bash-parser\src\index.js:52:9)
at Object.convertBashToWin (D:\bash-shell-to-bat-converter\lib\convert-
bash.js:69:36)
at Object. (D:\bash-shell-to-bat-converter\lib\cli.js:9:26)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)

Windows 10
node 10.15.1

arrays

arr=( "a1" "a2" "ai" ... ) doesn't work, returns parse error
neither does declare -a arr

Incorrect replacement of "." with "%CD%"

A portion of my *.sh was this:
TexturePacker --data ../dist/assets/spritesheets/symbols{v}.json

It was converted to this:

@echo off
TexturePacker "--data" "%CD%.\dist\assets\spritesheets\symbols{v}%CD%json"

This looks incorrect in two places. First, at the front of the path. The second place is just before the file extension.

Add LICENSE?

Hi, I was looking at using & extending this, but I don't see any LICENSE. Please add one!

I would recommend the MIT license, you can see that here: https://opensource.org/licenses/MIT#LicenseText

There are other good open source software licenses, including Apache 2.0, LGPL, and GPL. But please pick one.

I'll create a pull request to do this, but only you can decide if the license is what you want.

switch cases

original:

	case "$1" in
		"Darwin")
			javaFolder=~/"Library/Application Support/minecraft"
			bedrockFolder=~/"Library/Application Support/mcpelauncher/games/com.mojang"
			;;
		*)
			javaFolder=~/".minecraft"
			bedrockFolder=~/".var/app/io.mrarm.mcpelauncher/data/mcpelauncher/games/com.mojang"
			[[ ! -d "${bedrockFolder}" ]] && bedrockFolder=~/".local/share/mcpelauncher/games/com.mojang"
			;;
	esac

error code:

REM UNKNOWN: {"type":"Case","clause":{"text":"\"$1\"","expansion":[{"loc":{"start":1,"end":2},"parameter":1,"type":"ParameterExpansion","kind":"positional"}],"type":"Word"},"cases":[{"type":"CaseItem","pattern":[{"text":"Darwin","type":"Word"}],"body":{"type":"CompoundList","commands":[{"type":"Command","prefix":[{"text":"javaFolder=~/Library/Application Support/minecraft","type":"AssignmentWord"}]},{"type":"Command","prefix":[{"text":"bedrockFolder=~/Library/Application Support/mcpelauncher/games/com.mojang","type":"AssignmentWord"}]}]}},{"type":"CaseItem","pattern":[{"text":"*","type":"Word"}],"body":{"type":"CompoundList","commands":[{"type":"Command","prefix":[{"text":"javaFolder=~/.minecraft","type":"AssignmentWord"}]},{"type":"Command","prefix":[{"text":"bedrockFolder=~/.var/app/io.mrarm.mcpelauncher/data/mcpelauncher/games/com.mojang","type":"AssignmentWord"}]},{"type":"LogicalExpression","op":"and","left":{"type":"Command","name":{"text":"[[","type":"Word"},"suffix":[{"text":"!","type":"Word"},{"text":"-d","type":"Word"},{"text":"\"${bedrockFolder}\"","expansion":[{"loc":{"start":1,"end":16},"parameter":"bedrockFolder","type":"ParameterExpansion"}],"type":"Word"},{"text":"]]","type":"Word"}]},"right":{"type":"Command","prefix":[{"text":"bedrockFolder=~/.local/share/mcpelauncher/games/com.mojang","type":"AssignmentWord"}]}}]}}]}

Command IFS=',' read -r -a array <<< "$var" not working

O trecho do cรณdigo dรก erro quando tento converter para bat, dรก o seguinte erro: parse error: Error: Parse error on line 161: Unexpected 'LESS'
ou seja, linha:
IFS=',' read -r -a array <<< "$pastas_selecionadas"

   echo "Carregando arquivos da pasta.."
echo ""			
#listar_pasta=$(ls -1 | sed "s#^#${PWD}/#")
#echo "$listar_pasta"
echo ""
echo ""
echo "Escreva os nomes das pastas abaixo separando por vรญrgula."
read pastas_selecionadas;
IFS=',' read -r -a array <<< "$pastas_selecionadas"
arraylength=${#array[@]}
for (( i=1; i<${arraylength}+1; i++ ));
	do
		cd "${array[$i-1]}" 

Cannot read property 'start' of undefined

Getting this error when running the command to convert, also, might be related to this. The online version in the README also shows this error when you input a sh script

D:\bash-shell-to-bat-converter>node lib/cli.js modrelease.sh
converting file: modrelease.sh ...
D:\bash-shell-to-bat-converter\node_modules\bash-parser\src\index.js:52
                throw new Error(err.stack || err.message);
                ^
Error: TypeError: Cannot read property 'start' of undefined
    at Object.start [as previousReducer] (D:\bash-shell-to-bat-converter\node_modules\bash-parser\src\modes\posix\tokenizer\reducers\start.js:72:28)
    at expansionStart (D:\bash-shell-to-bat-converter\node_modules\bash-parser\src\modes\posix\tokenizer\reducers\expansion-start.js:38:15)
    at tokenizer (D:\bash-shell-to-bat-converter\node_modules\bash-parser\src\modes\posix\tokenizer\index.js:193:13)
    at tokenizer.next (<anonymous>)
    at Object.next (D:\bash-shell-to-bat-converter\node_modules\iterable-lookahead\index.js:51:24)
    at Object.next (D:\bash-shell-to-bat-converter\node_modules\map-iterable\index.js:33:30)
    at filterIterator (D:\bash-shell-to-bat-converter\node_modules\filter-iterator\index.js:6:12)
    at filterIterator.next (<anonymous>)
    at Object.next (D:\bash-shell-to-bat-converter\node_modules\map-iterable\index.js:33:30)
    at Object.next (D:\bash-shell-to-bat-converter\node_modules\iterable-lookahead\index.js:51:24)
    at Object.parse [as default] (D:\bash-shell-to-bat-converter\node_modules\bash-parser\src\index.js:52:9)
    at Object.convertBashToWin (D:\bash-shell-to-bat-converter\lib\convert-bash.js:109:36)
    at Object.<anonymous> (D:\bash-shell-to-bat-converter\lib\cli.js:9:26)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

and the error on the web version

parse error: Error: TypeError: Cannot read property 'start' of undefined
    at Object.LVmx.e.exports [as previousReducer] (https://daniel-sc.github.io/bash-shell-to-bat-converter/main-es2015.4a0ff3e228c4ecb17a52.js:1:160063)
    at Ny03.e.exports (https://daniel-sc.github.io/bash-shell-to-bat-converter/main-es2015.4a0ff3e228c4ecb17a52.js:1:164780)
    at https://daniel-sc.github.io/bash-shell-to-bat-converter/main-es2015.4a0ff3e228c4ecb17a52.js:1:154032
    at Generator.next (<anonymous>)
    at Object.next (https://daniel-sc.github.io/bash-shell-to-bat-converter/main-es2015.4a0ff3e228c4ecb17a52.js:1:536129)
    at Object.next (https://daniel-sc.github.io/bash-shell-to-bat-converter/main-es2015.4a0ff3e228c4ecb17a52.js:1:172319)
    at e.exports (https://daniel-sc.github.io/bash-shell-to-bat-converter/main-es2015.4a0ff3e228c4ecb17a52.js:1:213785)
    at e.exports.next (<anonymous>)
    at Object.next (https://daniel-sc.github.io/bash-shell-to-bat-converter/main-es2015.4a0ff3e228c4ecb17a52.js:1:172319)
    at Object.next (https://daniel-sc.github.io/bash-shell-to-bat-converter/main-es2015.4a0ff3e228c4ecb17a52.js:1:536129)

Support inline expressions

echo $(echo "test")

converts to:

@echo off

echo "%undefined%"

Even worse:

echo "$(echo "$(echo "test")")"

throws:

parse error: SyntaxError: Unclosed $(

REM UNKNOWN error emerges when using any kind of function

This happens in both the UI and via the cli.

Steps to reproduce:

  1. Go to https://daniel-sc.github.io/bash-shell-to-bat-converter/
  2. Enter this into the textbox
hisayer() {
echo "hi"
}
hisayer

Expected output (well, something like this, not necessarily like this)

@echo off
setlocal EnableDelayedExpansion
setlocal EnableExtensions

rem Function call
call :hisayer _0 0
echo | set /p ^=!_0!

goto :EOF
:hisayer
echo hi

Actual output:

REM UNKNOWN: {"type":"Function","name":{"text":"hisayer","type":"Name"},"body":{"type":"CompoundList","commands":[{"type":"Command","name":{"text":"echo","type":"Word"},"suffix":[{"text":"hi","type":"Word"}]}]}}
hisayer

Linux "export" should be changed to Windows "set"?

I love this utility it saved me a bunch of work, thank you. I noticed that Linux "export" is converted to Windows "export" and that did not work on Windows 11. I changed the "export" to "set" and it worked fine. Hope this helps.

the `cat EOF` problem

cat EOF is a method to write text to file that allows line breaks passing

yes I can replace it with hundreds of echo lines, but this method is bruh and time-wasting, and obviously cat EOF is the fastest and easiest way to write large amount of text to file

parse error: Error: Parse error on line 11: Unexpected 'OPEN_PAREN'

2023-08-31_12-02-48

# random screentone image generator
# python3 -m waifu2x.training.screentone_generator -n 100 -o ./screentone_test
from PIL import Image, ImageDraw
import random
import numpy as np
import argparse
from tqdm import tqdm
import os
from os import path
from torchvision import transforms as T
from torchvision.transforms import (
    functional as TF,
    InterpolationMode,
)


def ellipse_rect(center, size):
    return (center[0] - size // 2, center[1] - size // 2,
            center[0] + size // 2, center[1] + size // 2)


def random_crop(x, size):
    i, j, h, w = T.RandomCrop.get_params(x, size)
    x = TF.crop(x, i, j, h, w)
    return x


def random_interpolation(rotate=False):
    interpolations = [InterpolationMode.BILINEAR, InterpolationMode.BICUBIC]
    if rotate:
        interpolations.append(InterpolationMode.NEAREST)
    return random.choice(interpolations)


def gen_color(disable_color):
    line_masking = False
    line_overlay = None
    bg2 = None
    if (not disable_color) and random.uniform(0, 1) < 0.25:
        # random color
        bg = []
        for _ in range(3):
            bg.append(random.randint(0, 255))
        bg_mean = int(np.mean(bg))
        if bg_mean > 128:
            fg = np.clip([c - random.randint(32, 192) for c in bg], 0, 255)
        else:
            fg = np.clip([c + random.randint(32, 192) for c in bg], 0, 255)
        line = fg
        is_grayscale = random.uniform(0, 1) < 0.5
        if is_grayscale:
            fg_mean = int(np.mean(fg))
            fg = [fg_mean, fg_mean, fg_mean]
            bg = [bg_mean, bg_mean, bg_mean]
            line = fg
        if random.uniform(0, 1) < 0.1:
            if random.uniform(0, 1) < 0.5:
                line_overlay = tuple(line)
            else:
                line_masking = True
                line_overlay = tuple(bg)
    else:
        # black white
        if random.uniform(0, 1) < 0.8:
            c = random.randint(255 - 16, 255)
            bg = [c, c, c]
        else:
            c = random.randint(255 - 80, 255 - 16)
            bg = [c, c, c]
            c = random.randint(255 - 16, 255)
            bg2 = [c, c, c]
        if disable_color or random.uniform(0, 1) < 0.5:
            # black ink
            c = random.randint(0, 16)
            fg = [c, c, c]
            line = fg
            if random.uniform(0, 1) < 0.1:
                line_masking = True
                line_overlay = tuple(bg)
        else:
            # gray
            if random.uniform(0, 1) < 0.5:
                c = random.randint(0, 180)
            else:
                c = random.randint(80, 180)
            fg = [c, c, c]
            c = random.randint(0, 16)
            line = [c, c, c]
            if random.uniform(0, 1) < 0.1:
                # line overlay
                line_overlay = tuple(line)

    if bg2 is None:
        bg2 = bg
    return tuple(fg), tuple(bg), tuple(bg2), tuple(line), line_overlay, line_masking


def gen_mask(size=400):
    if random.uniform(0, 1) < 0.5:
        dot_size = random.choice([5, 7, 9, 11, 13])
    else:
        dot_size = random.choice([7, 9, 11, 13, 15, 17, 19, 21])
    p = random.uniform(0, 1)
    if p < 0.33:
        margin = random.randint(2, dot_size)
    elif p < 0.66:
        margin = random.randint(2, dot_size * 2)
    else:
        margin = random.choice([7, 9, 11, 13, 15, 17, 19])

    kernel_size = dot_size + margin
    kernel = Image.new("L", (kernel_size, kernel_size), "black")
    gc = ImageDraw.Draw(kernel)
    gc.ellipse(ellipse_rect((-1, -1), dot_size), fill="white")
    gc.ellipse(ellipse_rect((-1, kernel_size - 1), dot_size), fill="white")
    gc.ellipse(ellipse_rect((kernel_size - 1, -1), dot_size), fill="white")
    gc.ellipse(ellipse_rect((kernel_size - 1, kernel_size - 1), dot_size), fill="white")

    kernel = TF.to_tensor(kernel).squeeze(0)
    p = random.uniform(0, 1)
    if p < 0.4:
        # [o o]
        # [o o]
        repeat_y = repeat_x = (size * 2) // kernel_size
        grid = kernel.squeeze(0).repeat(repeat_y, repeat_x).unsqueeze(0)
        grid = TF.to_pil_image(grid)
        grid = random_crop(grid, (size, size))
    else:
        # [  o  ]
        # [o   o]
        # [  o  ]
        if p < 0.8:
            angle = 45
        else:
            angle = random.uniform(-180, 180)
        repeat_y = repeat_x = (size * 4) // kernel_size
        grid = kernel.squeeze(0).repeat(repeat_y, repeat_x).unsqueeze(0)
        grid = TF.to_pil_image(grid)
        grid = TF.rotate(grid, angle=angle, interpolation=random_interpolation(rotate=True))
        grid = TF.center_crop(grid, (size * 2, size * 2))
        grid = random_crop(grid, (size, size))

    return grid


def gen_line_overlay(size, line_scale=1):
    window = Image.new("L", (size * 2, size * 2), "black")
    if random.uniform(0, 1) < 0.5:
        line_width = random.randint(3, 8) * 2
    else:
        line_width = random.randint(3, 16) * 2
    line_width *= line_scale

    if random.uniform(0, 1) < 0.5:
        margin = random.randint(int(line_width * 0.75), line_width * 2)
    else:
        margin = random.randint(2, line_width * 4)
    offset = random.randint(0, 20)

    gc = ImageDraw.Draw(window)
    x = offset
    while x < window.width:
        gc.line(((x, 0), (x, window.height)), fill="white", width=line_width)
        x = x + line_width + margin

    angle = random.uniform(-180, 180)
    window = TF.rotate(window, angle=angle, interpolation=random_interpolation(rotate=True))
    window = TF.center_crop(window, (size, size))

    return window


IMAGE_SIZE = 640
WINDOW_SIZE = 400  # 320 < WINDOW_SIZE


def gen(disable_color):
    fg_color, window_bg_color, bg_color, line_color, line_overlay_color, line_masking = gen_color(disable_color)
    bg = Image.new("RGB", (WINDOW_SIZE * 2, WINDOW_SIZE * 2), window_bg_color)
    fg = Image.new("RGB", (WINDOW_SIZE * 2, WINDOW_SIZE * 2), fg_color)
    mask = gen_mask(WINDOW_SIZE * 2)
    bg.putalpha(255)
    fg.putalpha(mask)
    window = Image.alpha_composite(bg, fg)
    if line_overlay_color is not None:
        mask = gen_line_overlay(WINDOW_SIZE * 2, line_scale=4 if line_masking else 1)
        fg = Image.new("RGB", (WINDOW_SIZE * 2, WINDOW_SIZE * 2), line_overlay_color)
        window.putalpha(255)
        fg.putalpha(mask)
        window = Image.alpha_composite(window, fg)

    screen = Image.new("RGB", (IMAGE_SIZE * 2, IMAGE_SIZE * 2), bg_color)
    pad = (screen.height - window.height) // 2
    screen.paste(window, (pad, pad))
    gc = ImageDraw.Draw(screen)
    if random.uniform(0, 1) < 0.5:
        line_width = random.randint(4, 8) * 2
    else:
        line_width = random.randint(3, 12) * 2
    gc.rectangle((pad, pad, pad + window.width, pad + window.height), outline=line_color, width=line_width)

    screen = TF.resize(screen, (IMAGE_SIZE, IMAGE_SIZE), interpolation=random_interpolation(), antialias=True)

    return screen


def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("--num-samples", "-n", type=int, default=200,
                        help="number of images to generate")
    parser.add_argument("--seed", type=int, default=71, help="random seed")
    parser.add_argument("--postfix", type=str, help="filename postfix")
    parser.add_argument("--use-color", action="store_true", help="use random RGB color")
    parser.add_argument("--output-dir", "-o", type=str, required=True,
                        help="output directory")
    args = parser.parse_args()
    random.seed(args.seed)
    os.makedirs(args.output_dir, exist_ok=True)

    postfix = "_" + args.postfix if args.postfix else ""
    for i in tqdm(range(args.num_samples), ncols=80):
        im = gen(disable_color=not args.use_color)
        im.save(path.join(args.output_dir, f"__SCREENTONE_{i}{postfix}.png"))


if __name__ == "__main__":
    main()

Does this work well?

good morning
I tried this tool with simple code
However, the results were completely incorrect

bash code

#!/bin/bash
for i in */; do 7z a "${i%/}.zip" "$i"; done

Output code

@echo off
REM UNKNOWN: {"type":"For","name":{"text":"i","type":"Name"},"wordlist":[{"text":"*/","type":"Word"}],"do":{"type":"CompoundList","commands":[{"type":"Command","name":{"text":"7z","type":"Word"},"suffix":[{"text":"a","type":"Word"},{"text":"\"${i%/}.zip\"","expansion":[{"loc":{"start":1,"end":6},"parameter":"i","type":"ParameterExpansion","op":"removeSmallestSuffixPattern","word":{"text":"/","type":"Word"}}],"type":"Word"},{"text":"\"$i\"","expansion":[{"loc":{"start":1,"end":2},"parameter":"i","type":"ParameterExpansion"}],"type":"Word"}]}]}}

`for` and `while` loops not being converted

while true; do echo 1; done

turns into

REM UNKNOWN: {"type":"While","clause":{"type":"CompoundList","commands":[{"type":"Command","name":{"text":"true","type":"Word"}}]},"do":{"type":"CompoundList","commands":[{"type":"Command","name":{"text":"echo","type":"Word"},"suffix":[{"text":"1","type":"Word"}]}]}}

the same applied to for loop

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.