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

fixes issue #14 compiling on Win 7 now works #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 113 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,113 @@
*.swp
*.o
promptoglyph.tar.gz
promptoglyph-path
promptoglyph-vcs
*.swp
*.o
build/
.DS_Store
promptoglyph.tar.gz
promptoglyph-path
promptoglyph-vcs

# Created by https://www.gitignore.io/api/windows,sublimetext,osx,linux,d

### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk


### SublimeText ###
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# workspace files are user-specific
*.sublime-workspace

*.sublime-project

# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
# *.sublime-project

# sftp configuration file
sftp-config.json


### OSX ###
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*


### D ###
# Compiled Object files
*.o
*.obj

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Compiled Static libraries
*.a
*.lib

# Executables
*.exe

# DUB
.dub
docs.json
__dummy.html

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package: clean release
gzip -f9 promptoglyph.tar
rm -r promptoglyph

$(BUILD_DIR)/promptoglyph-path: promptoglyph-path.d help.d
$(BUILD_DIR)/promptoglyph-path: promptoglyph-path.d systempath.d help.d
Copy link
Owner

Choose a reason for hiding this comment

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

If systempath.d is only used in Windows and Windows uses a separate build script, why are we mentioning it in the Makefile?

@mkdir -p $(BUILD_DIR)
$(DC) $(DFLAGS) -of$@ $^

$(BUILD_DIR)/promptoglyph-vcs: promptoglyph-vcs.d help.d vcs.d time.d color.d git.d
$(BUILD_DIR)/promptoglyph-vcs: promptoglyph-vcs.d systempath.d help.d vcs.d time.d color.d git.d
@mkdir -p $(BUILD_DIR)
$(DC) $(DFLAGS) -of$@ $^

Expand Down
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,31 @@ but Probably Work™ since they only depend on vanilla C libraries

Alternatively, building form source is simple.

## How do I build it?
### Windows builds
Please build from source for now.

Grab a [D compiler](http://dlang.org/download.html) and run `make release`.
## How do I build it?
Grab a [D compiler](http://dlang.org/download.html) and follow the instructions for your platform below.
That's all.
There are no dependencies.

promptoglyph will be added as a [Dub](http://code.dlang.org) package soon-ish.


### Posix-compliant systems (like Linux, Mac OS X, etc.)
Just run `make release` and you should be set.

### Windows
Run `build.bat -r` to build the release version.
Run `build.bat -d` to build the debug version.


## How do I use it for my prompt?

Just invoke the programs with the desired options (see their `--help` info)
in your prompt expression.

### Posix-compliant systems (like Linux, Mac OS X, etc.)
In Zsh (for the prompt shown in the demo):

```shell
Expand All @@ -67,6 +79,38 @@ In Bash,
PS1="\$(promptoglyph-path) \$(promptoglyph-vcs --bash) % "
```

### Windows
For the default *cmd.exe* you are out of luck, as it does not support custom program execution and only has a limited number of available options.

Powershell on the other hand can use promptoglyph to enhance its prompt.
You will need to configure your [Powershell $profile](https://technet.microsoft.com/en-us/library/hh847857.aspx) to set your prompt accordingly.
Example Profile.ps1 (or Microsoft.PowerShell_profile.ps1) file:

```powershell
# may have to set this first: Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Set-ExecutionPolicy -ExecutionPolicy Unrestricted

# . $profile # ==> reload powershell config

function prompt
{
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal] $identity
# promptoglyph.exe must be available in the %PATH%
$git = & "promptoglyph-vcs.exe" 2>&1 | Out-String

$(if (test-path variable:/PSDebugContext) { '[DBG]: ' }

elseif($principal.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{ "[ADMIN]: " }

else { '' }) + 'PS ' + $(Get-Location) + ' ' + $git + $(if ($nestedpromptlevel -ge 1) { '>>' }) + '> '
}
```

For *Cygwin* you can use the compiled exe files and copy them into /usr/local/bin for example and then use them in your ~/.bashrc or ~/.profile configuration. Unfortunately colored output is not yet supported. Feel free to help improving the situation by digging into the code.


## It's 2015. Why are you generating a prompt with a compiled program?

I was using Zsh with [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh),
Expand Down
41 changes: 41 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@echo off
SETLOCAL ENABLEEXTENSIONS

REM -------------
REM I could not figure out a way to get DigitalMars' make.exe to like
REM the Unix style Makefile. If there is a way to change the Makefile
REM to allow both make.exe (by DigitalMars, comes with the D installation)
REM and make on Linux/Mac OS X to use it, please let me know.
REM -------------

REM no spaces between var name and assignment!
SET ME=%~n0
SET PARENT=%~dp0
SET BUILD_DIR=%PARENT%\build
SET DC=dmd
SET DFLAGS=-wi -g

IF /I "%1"=="/debug" GOTO LABEL_DEBUG
IF /I "%1"=="--debug" GOTO LABEL_DEBUG
IF /I "%1"=="-d" GOTO LABEL_DEBUG
IF /I "%1"=="/release" GOTO LABEL_RELEASE
IF /I "%1"=="--release" GOTO LABEL_RELEASE
IF /I "%1"=="-r" GOTO LABEL_RELEASE

GOTO LABEL_AFTER_VARIABLES
:LABEL_DEBUG
SET DFLAGS=%DFLAGS% -debug
GOTO LABEL_AFTER_VARIABLES
:LABEL_RELEASE
SET DFLAGS=%DFLAGS% -O -release

:LABEL_AFTER_VARIABLES

rmdir /s /q %BUILD_DIR%
mkdir %BUILD_DIR%

echo on

%DC% %DFLAGS% -of%BUILD_DIR%\promptoglyph-vcs.exe promptoglyph-vcs.d systempath.d help.d vcs.d time.d color.d git.d
%DC% %DFLAGS% -of%BUILD_DIR%\promptoglyph-path.exe promptoglyph-path.d systempath.d help.d

22 changes: 21 additions & 1 deletion color.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ alias UseColor = Flag!"UseColor";
enum Escapes {
none,
bash,
zsh
zsh,
cmd
}

mixin(makeColorFunction("cyan", 36));
Expand All @@ -16,6 +17,23 @@ mixin(makeColorFunction("resetColor", 39));

private:

// Getting colored chars into the cmd.exe command line window is nearly impossible. :-(
// http://superuser.com/questions/427820/how-to-change-only-the-prompt-color-of-the-windows-command-line
// Quoting:
//
// Following the prompt of @Luke I finally get the solution. Anyone who is interested in this topic please hit the two links below:
//
// Color for the PROMPT (just the PROMPT proper) in cmd.exe and PowerShell? & http://gynvael.coldwind.pl/?id=130
//
// It is "ANSI hack developped for the CMD.exe shell".
//
//
// However, it seems possible to do if the user is using Powershell instead of cmd.exe:
// http://stackoverflow.com/a/20666813/193165
//
// TODO(dkg): cmd.exe is not really suited for this tool anyway, but Powershell is, so we
// should see if we can add colors for powershell.
// TODO(dkg): support colors for bash, zsh, etc. in Cygwin
string makeColorFunction(string name, int code)
{
import std.conv : to;
Expand All @@ -31,6 +49,8 @@ string makeColorFunction(string name, int code)
return bashEscape(ret);
case Escapes.zsh:
return zshEscape(ret);
case Escapes.cmd:
return "";
}
}
`;
Expand Down
Loading