Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Bartlomiej Specjalny <bspecjalny@gmail.com>
  • Loading branch information
sp3c1 committed Apr 27, 2018
1 parent 4ea0f01 commit 1a7d206
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 76 deletions.
79 changes: 45 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,75 +13,86 @@ The look is inspired by [Powerline for Vim](https://github.com/powerline/powerli
# Requirements

Download the [AnonymousPro font](https://github.com/powerline/fonts/tree/master/AnonymousPro)
You'll be able to use any font in Cmder, but this font contains the symbols included in the prompt.
You'll be able to use any font in Cmder, but this font contains the symbols included in the prompt.

## Font
To use another font and still show symbols correctly:
- Go to Cmder Settings > Main
- Choose Main console font to be what you prefer
- Choose _Alternative font_ to be _Anonymice Powerline_
- Modify the value of _Unicode ranges_ to add: `E0A0; E0B0;`
- Save Settings

To use another font and still show symbols correctly:

* Go to Cmder Settings > Main
* Choose Main console font to be what you prefer
* Choose _Alternative font_ to be _Anonymice Powerline_
* Modify the value of _Unicode ranges_ to add: `E0A0; E0B0;`
* for extra symbols set in `powerline_config.lua` (like npm logo for node module or git project for smart path resolving) set the _Alternative font_ to one of your choosing.
![screenshot](fonts.png)
* Save Settings

# Usage

Download the `.lua` file, and place it in `%CMDER_ROOT%/config` folder.
Restart Cmder to load the prompt.

__Alternatively__, if you want to maintain link with the original repo, you can clone this repo into any folder
**Alternatively**, if you want to maintain link with the original repo, you can clone this repo into any folder
`git clone https://github.com/AmrEldib/cmder-powerline-prompt.git git-repo-folder-name`
then create a symbolic link from the `%CMDER_ROOT%/config` folder to the `.lua` file.
then create a symbolic link from the `%CMDER_ROOT%/config` folder to the `.lua` file.

```
cd %CMDER_ROOT%/config
mklink /H cmder-powerline-prompt.lua <git-repo-folder-name>/cmder-powerline-prompt.lua
```
mklink /H cmder-powerline-prompt.lua <git-repo-folder-name>/cmder-powerline-prompt.lua
```

## Configuration

You can modify the prompt to display either the full path or only the folder name.
To do this, modify the value of the `promptValue` variable in the `powerline_prompt.lua` file at [this line](https://github.com/AmrEldib/cmder-powerline-prompt/blob/master/powerline_prompt.lua#L10)
The value could be either:
- `promptValueFull` for full path like `C:\Windows\System32`
- `promptValueFolder` for folder name only like `System32`
The value could be either:

* `promptValueFull` for full path like `C:\Windows\System32`
* `promptValueFolder` for folder name only like `System32`

`promptValueFull` is the default.
`promptValueFull` is the default.

# Helpful info for customizing Cmder
# Helpful info for customizing Cmder

## Links

[Cmder Source Code and README](https://github.com/cmderdev/cmder)
[What is Clink](https://github.com/AmrEldib/cmder-powerline-prompt/blob/master/docs/clink.md)
[Clink Lua API](https://github.com/AmrEldib/cmder-powerline-prompt/blob/master/docs/clink_api.md)
[ANSI Color Sequence](http://ascii-table.com/ansi-escape-sequences.php)
[ANSI Color Sequence](http://ascii-table.com/ansi-escape-sequences.php)

## Cmder Configurations

Cmder configurations is stored in `%CMDER_ROOT%\config\`
You can add files to be loaded during startup in either of these folders
`%CMDER_ROOT%\config\profile.d`
`%CMDER_ROOT%\config`
`%CMDER_ROOT%\config\profile.d`
`%CMDER_ROOT%\config`
Add a `.ps1` file to be loaded for Powershell shells
Add a `.bat` or `.cmd` files to be loaded for Windows Command shells
Add a `.sh` file to be loaded for Bash shells
User-specific configurations should go into files named `user-profile` with extensions `ps1`, `cmd`/`bat`, or `sh`.
User-specific configurations should go into files named `user-profile` with extensions `ps1`, `cmd`/`bat`, or `sh`.

## Clink Prompt

## Clink Prompt
The file `%CMDER_ROOT%\vendor\clink.lua` sets the command prompt. See the function `set_prompt_filter`.
The prompt value is stored in [clink.prompt.value](https://github.com/mridgers/clink/blob/master/docs/api.md#clinkpromptvalue)
Drop .lua files into the `%CMDER_ROOT%\Config` folder to customize the prompt.

# Status & Contribution
I published this code because it's not nice to keep it to myself. I fix problems that I encounter, and try to fix problems that others encounter if I have time.
This code is provided with the timeless __Works on my Machine__ gurentee.
You can also check out the [pull requests page](/pulls) for contributions that didn't make back into this repo. These are fixes to problems I didn't encounter, or features not useful to me, but maybe useful to you.

I published this code because it's not nice to keep it to myself. I fix problems that I encounter, and try to fix problems that others encounter if I have time.
This code is provided with the timeless **Works on my Machine** gurentee.
You can also check out the [pull requests page](/pulls) for contributions that didn't make back into this repo. These are fixes to problems I didn't encounter, or features not useful to me, but maybe useful to you.

People are very kind and contribute back fixes and improvements.
This section is to acknowledage their contributions and thank them. If you find their contributions helpful to you, please take the time to thank them directly.
- [omniphx](https://github.com/omniphx) [#2](https://github.com/AmrEldib/cmder-powerline-prompt/pull/2)
- [umar-ahmed](https://github.com/umar-ahmed) [#6](https://github.com/AmrEldib/cmder-powerline-prompt/pull/6)
- [tvercruysse](https://github.com/tvercruysse) [#10](https://github.com/AmrEldib/cmder-powerline-prompt/pull/10)
- [igortg](https://github.com/igortg) [#24](https://github.com/AmrEldib/cmder-powerline-prompt/pull/24)
- [0NG](https://github.com/0NG) [#27](https://github.com/AmrEldib/cmder-powerline-prompt/pull/27)
- [mattdkerr](https://github.com/mattdkerr) [#29](https://github.com/AmrEldib/cmder-powerline-prompt/pull/29)
- [ivanjonas](https://github.com/ivanjonas) [#32](https://github.com/AmrEldib/cmder-powerline-prompt/pull/32)

I'd like to thank all who share their code with everyone for their time and effort.
This section is to acknowledage their contributions and thank them. If you find their contributions helpful to you, please take the time to thank them directly.

* [omniphx](https://github.com/omniphx) [#2](https://github.com/AmrEldib/cmder-powerline-prompt/pull/2)
* [umar-ahmed](https://github.com/umar-ahmed) [#6](https://github.com/AmrEldib/cmder-powerline-prompt/pull/6)
* [tvercruysse](https://github.com/tvercruysse) [#10](https://github.com/AmrEldib/cmder-powerline-prompt/pull/10)
* [igortg](https://github.com/igortg) [#24](https://github.com/AmrEldib/cmder-powerline-prompt/pull/24)
* [0NG](https://github.com/0NG) [#27](https://github.com/AmrEldib/cmder-powerline-prompt/pull/27)
* [mattdkerr](https://github.com/mattdkerr) [#29](https://github.com/AmrEldib/cmder-powerline-prompt/pull/29)
* [ivanjonas](https://github.com/ivanjonas) [#32](https://github.com/AmrEldib/cmder-powerline-prompt/pull/32)

I'd like to thank all who share their code with everyone for their time and effort.
10 changes: 7 additions & 3 deletions _powerline_config.lua.sample
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ arrowSymbol = ""
lambSymbol = "λ"
newLineSymbol = "\n"
branchSymbol = ""
githubSymbol = ""
npmSymbol = ""
nodeSymbol = ""
githubSymbol = "GIT"
npmSymbol = "NPM"
nodeSymbol = "NODE"


delayGit = 61
delayNpm = 60
Binary file added fonts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions powerline_core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,52 @@ function closePrompt()
clink.prompt.value = clink.prompt.value..newLineSymbol..lambSymbol.." "
end

---
-- Gets the .git directory
-- copied from clink.lua
-- clink.lua is saved under %CMDER_ROOT%\vendor
-- @return {bool} indicating there's a git directory or not
---
function get_git_dir(path)

-- return parent path for specified entry (either file or directory)
local function pathname(path)
local prefix = ""
local i = path:find("[\\/:][^\\/:]*$")
if i then
prefix = path:sub(1, i-1)
end
return prefix
end

-- Checks if provided directory contains git directory
local function has_git_dir(dir)
return clink.is_dir(dir..'/.git') and dir..'/.git'
end

local function has_git_file(dir)
local gitfile = io.open(dir..'/.git')
if not gitfile then return false end

local git_dir = gitfile:read():match('gitdir: (.*)')
gitfile:close()

return git_dir and dir..'/'..git_dir
end

-- Set default path to current directory
if not path or path == '.' then path = clink.get_cwd() end

-- Calculate parent path now otherwise we won't be
-- able to do that inside of logical operator
local parent_path = pathname(path)

return has_git_dir(path)
or has_git_file(path)
-- Otherwise go up one level and make a recursive call
or (parent_path ~= path and get_git_dir(parent_path) or nil)
end

-- Register filters for resetting the prompt and closing it before and after all addons
clink.prompt.register_filter(resetPrompt, 51)
clink.prompt.register_filter(closePrompt, 99)
41 changes: 2 additions & 39 deletions powerline_git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,45 +38,8 @@ end
-- clink.lua is saved under %CMDER_ROOT%\vendor
-- @return {bool} indicating there's a git directory or not
---
function get_git_dir(path)

-- return parent path for specified entry (either file or directory)
local function pathname(path)
local prefix = ""
local i = path:find("[\\/:][^\\/:]*$")
if i then
prefix = path:sub(1, i-1)
end
return prefix
end

-- Checks if provided directory contains git directory
local function has_git_dir(dir)
return clink.is_dir(dir..'/.git') and dir..'/.git'
end

local function has_git_file(dir)
local gitfile = io.open(dir..'/.git')
if not gitfile then return false end

local git_dir = gitfile:read():match('gitdir: (.*)')
gitfile:close()

return git_dir and dir..'/'..git_dir
end

-- Set default path to current directory
if not path or path == '.' then path = clink.get_cwd() end

-- Calculate parent path now otherwise we won't be
-- able to do that inside of logical operator
local parent_path = pathname(path)

return has_git_dir(path)
or has_git_file(path)
-- Otherwise go up one level and make a recursive call
or (parent_path ~= path and get_git_dir(parent_path) or nil)
end
-- function get_git_dir(path)
-- MOVED INTO CORE

---
-- Gets the status of working dir
Expand Down

0 comments on commit 1a7d206

Please sign in to comment.