Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --new-script option to gmt #1481

Merged
merged 12 commits into from
Sep 3, 2019
Merged

Add --new-script option to gmt #1481

merged 12 commits into from
Sep 3, 2019

Conversation

PaulWessel
Copy link
Member

This option will write a modern mode script template to stdout in either bash or csh format. We could extend this to DOS batch if we can detect the Windows command window (?). Not tested by a user whose default shell is csh or tcsh.

This option will write a modern mode script template to stdout in either bash or csh format.  We could extend this to DOS batch if we can detect the Windows command window (?).
@PaulWessel
Copy link
Member Author

Partially addresses the issues raised in #1299.

src/gmt.c Outdated Show resolved Hide resolved
src/gmt.c Outdated Show resolved Hide resolved
@joa-quim
Copy link
Member

joa-quim commented Sep 2, 2019

Yes, DOS batch should be a possible output too. On Win most of times a .bat is all one needs.

@PaulWessel
Copy link
Member Author

How do we know one is running gmt under Windows command window (and want a batch) rather than in a bash shell?

@joa-quim
Copy link
Member

joa-quim commented Sep 2, 2019

Well, under Win one should default to .bat. But we can print also the unix shebang line but commented out. Like this a Win user that wants a bash can easily uncomment that line and comment the @echo off one.

@PaulWessel
Copy link
Member Author

I guess if Windows and if getenv ("shell") or getenv ("SHELL") are not defined then we are likely in Windows command window. What does echo %SHELL% or echo %shell% give you, if anything?

@seisman
Copy link
Member

seisman commented Sep 2, 2019

%SHELL% and %shell% give nothing.
image

@PaulWessel
Copy link
Member Author

OK, so presumably that is a good test to run under #ifdef WINDOWs and if none are set then we write a batch script.

Improved formatting of script
@PaulWessel
Copy link
Member Author

See what you guys think. I cannot easily test apart from bash.

@joa-quim
Copy link
Member

joa-quim commented Sep 2, 2019

Busy with the proj.db shit.

Also use the PPID instead of $$ under Windows.
Fix a few missing items in gmt.rst plus add the new-script option.
Copy link
Member

@seisman seisman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I get with Windows CMD.

REM GMT modern mode batch template
REM Date:    2019-09-02T22:36:58
REM User:    unknown
REM Purpose: Purpose of this script
REM Set a unique session name:
set GMT_SESSION_NAME 5372
gmt begin figurename
        REMPlace modern session commands here
gmt end show

There are at least two errors here, and I've made the suggestions.

src/gmt.c Outdated Show resolved Hide resolved
src/gmt.c Outdated Show resolved Hide resolved
PaulWessel and others added 3 commits September 2, 2019 16:46
Co-Authored-By: Dongdong Tian <[email protected]>
via GetUserName function.
@PaulWessel
Copy link
Member Author

OK, I fixed those two. Updated gmt_putusername to work under Windows - please test.

Needed by GetUserName
@seisman
Copy link
Member

seisman commented Sep 3, 2019

Bash on macOS:

#!/usr/bin/env bash
# GMT modern mode bash template
# Date:    2019-09-02T22:50:24
# User:    seisman
# Purpose: Purpose of this script
export GMT_SESSION_NAME=$$	# Set a unique session name
gmt begin figurename
	# Place modern session commands here
gmt end show

csh on macOS:

#!/usr/bin/env csh
# GMT modern mode csh template
# Date:    2019-09-02T23:29:14
# User:    seisman
# Purpose: Purpose of this script
setenv GMT_SESSION_NAME $$	# Set a unique session name
gmt begin figurename
	# Place modern session commands here
gmt end show

CMD on Windows:

REM GMT modern mode batch template
REM Date:    2019-09-02T23:34:25
REM User:    unknown
REM Purpose: Purpose of this script
REM Set a unique session name:
set GMT_SESSION_NAME=7492
gmt begin figurename
        REM Place modern session commands here
gmt end show

Git-Bash on Windows:

#!/usr/bin/env bash
# GMT modern mode bash template
# Date:    2019-09-02T23:35:36
# User:    unknown
# Purpose: Purpose of this script
export GMT_SESSION_NAME=$$      # Set a unique session name
gmt begin figurename
        # Place modern session commands here
gmt end show

@seisman
Copy link
Member

seisman commented Sep 3, 2019

Looks good, except the username is still unknown on Windows.

@PaulWessel
Copy link
Member Author

Does echo %USERNAME% give anything useful in Windows?

@seisman
Copy link
Member

seisman commented Sep 3, 2019

Yes, %USERNAME% gives the correct username in CMD, and also $USERNAME in git-bash.

Since GetUesrName may not always work (?).
src/gmt_support.c Outdated Show resolved Hide resolved
Co-Authored-By: Dongdong Tian <[email protected]>
Copy link
Member

@seisman seisman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the username is correct on Windows.

@PaulWessel PaulWessel changed the title WIP Add --new-script option to gmt Add --new-script option to gmt Sep 3, 2019
@PaulWessel PaulWessel merged commit 954bb96 into 6.0 Sep 3, 2019
@PaulWessel PaulWessel deleted the newscript branch September 3, 2019 04:15
@joa-quim
Copy link
Member

joa-quim commented Sep 3, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants