mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
feat: initial commit
This commit is contained in:
commit
c4d1c75781
1
commitlint.config.js
Normal file
1
commitlint.config.js
Normal file
|
@ -0,0 +1 @@
|
|||
module.exports = { extends: ['@commitlint/config-conventional'] };
|
5
.github/FUNDING.yml
vendored
Normal file
5
.github/FUNDING.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
# These are supported funding model platforms
|
||||
|
||||
patreon: jandedobbeleer
|
||||
liberapay: jandedobbeleer
|
||||
custom: https://ko-fi.com/jandedobbeleer
|
49
.github/workflows/code.yml
vendored
Normal file
49
.github/workflows/code.yml
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
on:
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- 'README.md'
|
||||
- 'docs/**'
|
||||
|
||||
name: Validate Code
|
||||
jobs:
|
||||
test:
|
||||
env:
|
||||
GOPATH: ${{ github.workspace }}
|
||||
GO111MODULE: off
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
INSTALL_DEP: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
|
||||
- os: macos-latest
|
||||
INSTALL_DEP: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
|
||||
- os: windows-latest
|
||||
INSTALL_DEP: choco install dep
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.15.x
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: ./src/github.com/${{ github.repository }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
${{ matrix.INSTALL_DEP }}
|
||||
dep ensure -v
|
||||
- name: Install dependencies
|
||||
run: dep ensure -v
|
||||
- name: Golang CI
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
with:
|
||||
version: v1.31
|
||||
working-directory: ./src/github.com/${{ github.repository }}
|
||||
- name: Unit Tests
|
||||
run: go test . -v
|
12
.github/workflows/commits.yml
vendored
Normal file
12
.github/workflows/commits.yml
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
name: Validate Commits
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
commitlint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: wagoid/commitlint-github-action@v2
|
95
.github/workflows/release.yml
vendored
Normal file
95
.github/workflows/release.yml
vendored
Normal file
|
@ -0,0 +1,95 @@
|
|||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths-ignore:
|
||||
- 'README.md'
|
||||
- 'docs/**'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Get next version
|
||||
id: version
|
||||
run: |
|
||||
curl -L https://github.com/idc101/git-mkver/releases/download/v$MKVER/git-mkver-darwin-amd64-$MKVER.tar.gz | tar xvz
|
||||
sudo mv git-mkver /usr/local/bin
|
||||
echo "::set-output name=version::$(git mkver next)"
|
||||
env:
|
||||
MKVER: "1.1.1"
|
||||
- name: Create changelog
|
||||
id: changelog
|
||||
uses: TriPSs/conventional-changelog-action@v3
|
||||
with:
|
||||
github-token: ${{ secrets.github_token }}
|
||||
skip-version-file: "true"
|
||||
output-file: "false"
|
||||
skip-commit: "true"
|
||||
fallback-version: ${{ steps.version.outputs.version }}
|
||||
- name: Create Github Release
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
if: ${{ steps.changelog.outputs.skipped == 'false' }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.github_token }}
|
||||
with:
|
||||
tag_name: ${{ steps.changelog.outputs.tag }}
|
||||
release_name: ${{ steps.changelog.outputs.tag }}
|
||||
body: ${{ steps.changelog.outputs.clean_changelog }}
|
||||
artifacts:
|
||||
needs: release
|
||||
env:
|
||||
GOPATH: ${{ github.workspace }}
|
||||
GO111MODULE: off
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
ARTIFACT: posh-linux-amd64
|
||||
INSTALL_DEP: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
|
||||
- os: macos-latest
|
||||
ARTIFACT: posh-darwin-amd64
|
||||
INSTALL_DEP: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
|
||||
- os: windows-latest
|
||||
ARTIFACT: posh-windows-amd64.exe
|
||||
INSTALL_DEP: choco install dep
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.15.x
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: ./src/github.com/${{ github.repository }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
${{ matrix.INSTALL_DEP }}
|
||||
dep ensure -v
|
||||
- name: Build
|
||||
id: build
|
||||
run: go build -o ${{ matrix.ARTIFACT }}
|
||||
env:
|
||||
GOARCH: "amd64"
|
||||
- name: Upload Release Asset
|
||||
id: upload-release-asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ needs.release.outputs.upload_url }}
|
||||
asset_path: ./src/github.com/${{ github.repository }}/${{ matrix.ARTIFACT }}
|
||||
asset_name: ${{ matrix.ARTIFACT }}
|
||||
asset_content_type: application/octet-stream
|
147
.gitignore
vendored
Executable file
147
.gitignore
vendored
Executable file
|
@ -0,0 +1,147 @@
|
|||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/node,go,visualstudiocode
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=node,go,visualstudiocode
|
||||
|
||||
### Go ###
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
### Go Patch ###
|
||||
/vendor/
|
||||
/Godeps/
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/node,go,visualstudiocode
|
18
.vscode/launch.json
vendored
Executable file
18
.vscode/launch.json
vendored
Executable file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}/main.go",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {},
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
}
|
674
COPYING
Normal file
674
COPYING
Normal file
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
123
Gopkg.lock
generated
Executable file
123
Gopkg.lock
generated
Executable file
|
@ -0,0 +1,123 @@
|
|||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec"
|
||||
name = "github.com/davecgh/go-spew"
|
||||
packages = ["spew"]
|
||||
pruneopts = "UT"
|
||||
revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73"
|
||||
version = "v1.1.1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:aca47c80c4e1d2e2a1510d387eacefd10b5d96a53b851b482dc8d186f6de4d30"
|
||||
name = "github.com/distatus/battery"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "bb0a7566dbb8123391059c4d040baf50cd3e15a5"
|
||||
source = "github.com/JanDeDobbeleer/battery"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:eba10af56a904e7d797ccbdca4a6fae4029537b0118b6582f9f93e025b86af2a"
|
||||
name = "github.com/imdario/mergo"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "cd55aeac72a19c6d5826061d5125d72b252a12eb"
|
||||
version = "v0.3.11"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe"
|
||||
name = "github.com/pmezard/go-difflib"
|
||||
packages = ["difflib"]
|
||||
pruneopts = "UT"
|
||||
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:86ff4af7b6bb3d27c2e89b5ef8c139678acff1cad74a3c5235fc5af6b94fcc9e"
|
||||
name = "github.com/stretchr/objx"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "35313a95ee26395aa17d366c71a2ccf788fa69b6"
|
||||
version = "v0.3.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:e1dec70f3d761a66432fa0c7f2b38a63cbe9d91761a50102def809ecf133cec4"
|
||||
name = "github.com/stretchr/testify"
|
||||
packages = [
|
||||
"assert",
|
||||
"mock",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "f654a9112bbeac49ca2cd45bfbe11533c4666cf8"
|
||||
source = "github.com/stretchr/testify"
|
||||
version = "v1.6.1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:9d459f92935fefb74c8f24dc81230a4adbe5c8a94004adbfc8f826596c0e6a16"
|
||||
name = "golang.org/x/sys"
|
||||
packages = [
|
||||
"internal/unsafeheader",
|
||||
"unix",
|
||||
"windows",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "9781c653f44323e2079cb1123720c32f9626be2c"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:a2c690dfee42801a26a0e88f69206feca8a3c2437fd476d84767468d7d7708e9"
|
||||
name = "golang.org/x/text"
|
||||
packages = [
|
||||
"internal/gen",
|
||||
"internal/triegen",
|
||||
"internal/ucd",
|
||||
"transform",
|
||||
"unicode/cldr",
|
||||
"unicode/norm",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "23ae387dee1f90d29a23c0e87ee0b46038fbed0e"
|
||||
source = "golang.org/x/text"
|
||||
version = "v0.3.3"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:72f36cc57d0bdd5425e90d637d83bae9479ccc972364a21cde79ddfe72f7ac40"
|
||||
name = "gopkg.in/gookit/color.v1"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "dedbfedb6650e743179e81a3a4cafddbd57da08e"
|
||||
source = "gopkg.in/gookit/color.v1"
|
||||
version = "v1.2.7"
|
||||
|
||||
[[projects]]
|
||||
branch = "v3"
|
||||
digest = "1:229cb0f6192914f518cc1241ede6d6f1f458b31debfa18bf3a5c9e4f7b01e24b"
|
||||
name = "gopkg.in/yaml.v3"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "eeeca48fe7764f320e4870d231902bf9c1be2c08"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:b5ead2120cd278858a83be14ef551f54295da350033dbc3f227fe0298b880256"
|
||||
name = "howett.net/plist"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "3b63eb3a43b59c776909681ed1fcb412b47d3c9a"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
input-imports = [
|
||||
"github.com/distatus/battery",
|
||||
"github.com/imdario/mergo",
|
||||
"github.com/stretchr/testify/assert",
|
||||
"github.com/stretchr/testify/mock",
|
||||
"golang.org/x/sys/windows",
|
||||
"golang.org/x/text/unicode/norm",
|
||||
"gopkg.in/gookit/color.v1",
|
||||
]
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
57
Gopkg.toml
Executable file
57
Gopkg.toml
Executable file
|
@ -0,0 +1,57 @@
|
|||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
#
|
||||
# [prune]
|
||||
# non-go = false
|
||||
# go-tests = true
|
||||
# unused-packages = true
|
||||
|
||||
[[constraint]]
|
||||
name = "gopkg.in/gookit/color.v1"
|
||||
source = "gopkg.in/gookit/color.v1"
|
||||
|
||||
[[constraint]]
|
||||
version = "v0.3.3"
|
||||
name = "golang.org/x/text"
|
||||
source = "golang.org/x/text"
|
||||
|
||||
[[constraint]]
|
||||
version = "v0.3.7"
|
||||
name = "github.com/imdario/mergo"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/stretchr/testify"
|
||||
version = "1.3.0"
|
||||
source = "github.com/stretchr/testify"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/stretchr/objx"
|
||||
version = "v0.1.1"
|
||||
source = "github.com/stretchr/objx"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/distatus/battery"
|
||||
branch = "master"
|
||||
source = "github.com/JanDeDobbeleer/battery"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
169
README.md
Normal file
169
README.md
Normal file
|
@ -0,0 +1,169 @@
|
|||
# A prompt theme engine for any shell
|
||||
|
||||
![example workflow name](https://github.com/jandedobbeleer/go-my-posh/workflows/Release/badge.svg)
|
||||
[![Go Report Card](https://goreportcard.com/badge/github.com/jandedobbeleer/go-my-posh)](https://goreportcard.com/report/github.com/jandedobbeleer/go-my-posh)
|
||||
|
||||
What started as the offspring of [oh-my-posh][oh-my-posh] for PowerShell resulted in a cross platform, highly customizable and extensible prompt theme engine. After 4 years of working on oh-my-posh, a modern and more efficient tool was needed to suit my personal needs.
|
||||
|
||||
## ❤ Support ❤
|
||||
|
||||
[![Patreon][patreon-badge]][patreon]
|
||||
[![Liberapay][liberapay-badge]][liberapay]
|
||||
[![Ko-Fi][kofi-badge]][kofi]
|
||||
|
||||
## Features
|
||||
|
||||
* Git status indications
|
||||
* Failed command indication
|
||||
* Admin indication
|
||||
* Current session indications
|
||||
* Configurable
|
||||
|
||||
## Table of Contents**
|
||||
|
||||
* [Installation](#installation)
|
||||
* [Precompiled Binaries](#precompiled-binaries)
|
||||
* [PowerShell](#powershell)
|
||||
* [ZSH](#zsh)
|
||||
* [Bash](#bash)
|
||||
* [Fish](#fish)
|
||||
* [Nix](#nix)
|
||||
* [Configuration](#configuration)
|
||||
* [Roadmap](#roadmap)
|
||||
* [Thanks](#thanks)
|
||||
|
||||
## Installation
|
||||
|
||||
`go-my-posh` uses ANSI color codes under the hood, these should work everywhere,
|
||||
but you may have to set your $TERM to `xterm-256color` for it to work.
|
||||
|
||||
For maximum enjoyment, make sure to install a powerline enabled font. The fonts I use are patched by [Nerd Fonts][nerdfonts], which offers a maximum of icons you can use to configure your prompt.
|
||||
|
||||
### Precompiled Binaries
|
||||
|
||||
You can find precompiled binaries for all major OS's underneath the
|
||||
[releases tab][releases]. Installation instruction for the different shells below assumes `<go-my-posh>` points to the go-my-posh binary and you've downloaded the [`jandedobbeleer` theme][jandedobbeleer] to your `$HOME` directory.
|
||||
|
||||
On UNIX systems, make sure the binary is executable before using it.
|
||||
|
||||
```bash
|
||||
chmod +x gmp_executable
|
||||
```
|
||||
|
||||
### Bash
|
||||
|
||||
Add the following to your `.bashrc` (or `.profile` on Mac):
|
||||
|
||||
```bash
|
||||
function _update_ps1() {
|
||||
PS1="$(<go-my-posh> -error $?)"
|
||||
}
|
||||
|
||||
if [ "$TERM" != "linux" ] && [ -f <go-my-posh> ]; then
|
||||
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
|
||||
fi
|
||||
```
|
||||
|
||||
### ZSH
|
||||
|
||||
Add the following to your `.zshrc`:
|
||||
|
||||
```bash
|
||||
function powerline_precmd() {
|
||||
PS1="$(<go-my-posh> -config ~/jandedobbeleer.json --error $?)"
|
||||
}
|
||||
|
||||
function install_powerline_precmd() {
|
||||
for s in "${precmd_functions[@]}"; do
|
||||
if [ "$s" = "powerline_precmd" ]; then
|
||||
return
|
||||
fi
|
||||
done
|
||||
precmd_functions+=(powerline_precmd)
|
||||
}
|
||||
|
||||
if [ "$TERM" != "linux" ]; then
|
||||
install_powerline_precmd
|
||||
fi
|
||||
```
|
||||
|
||||
### Fish
|
||||
|
||||
Redefine `fish_prompt` in `~/.config/fish/config.fish`:
|
||||
|
||||
```bash
|
||||
function fish_prompt
|
||||
eval <go-my-posh> -config ~/jandedobbeleer.json -error $status
|
||||
end
|
||||
```
|
||||
|
||||
### Nix
|
||||
|
||||
When using `nix-shell --pure`, `go-my-posh` will not be accessible, and
|
||||
your prompt will not appear.
|
||||
|
||||
As a workaround you can add this snippet to your `.bashrc`,
|
||||
which should re-enable the prompt in most cases:
|
||||
|
||||
```bash
|
||||
# Workaround for nix-shell --pure
|
||||
if [ "$IN_NIX_SHELL" == "pure" ]; then
|
||||
if [ -x <go-my-posh> ]; then
|
||||
alias powerline-go="<go-my-posh> -config ~/jandedobbeleer.json"
|
||||
fi
|
||||
fi
|
||||
```
|
||||
|
||||
### Powershell
|
||||
|
||||
Redefine `prompt` function on your profile:
|
||||
|
||||
```powershell
|
||||
[ScriptBlock]$Prompt = {
|
||||
$err = $? ? 0 : 1
|
||||
<go-my-posh> -config ~/jandedobbeleer.json -error $err
|
||||
}
|
||||
Set-Item -Path Function:prompt -Value $Prompt -Force
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
As the documentation for all the different segments is still lacking, have a look at the available [themes][themes] for reference.
|
||||
|
||||
Every segment has its own properties you can set/override. Have a look at the code for any you would want to tweak, available options
|
||||
are listed as the `Property` constant with their respective `JSON` notation for use in a segment's `properties` section. Additionally,
|
||||
a few general properties are available cross segments which can be found in `properties.go`.
|
||||
|
||||
## Roadmap
|
||||
|
||||
* [x] CI
|
||||
* [x] Github Releases
|
||||
* [x] Create documentation for manual installation
|
||||
* [ ] Create documentation on the different segments
|
||||
* Create easy installation packages
|
||||
* [ ] Brew
|
||||
* [ ] Chocolatey
|
||||
* [ ] Create documentation on the different segments
|
||||
|
||||
## Thanks
|
||||
|
||||
* [Chris Benti][chrisbenti-psconfig] for providing the first influence to start oh-my-posh
|
||||
* [Keith Dahlby][keithdahlby-poshgit] for creating posh-git and making life more enjoyable
|
||||
* [Robby Russel][oh-my-zsh] for creating oh-my-zsh, without him this would probably not be here
|
||||
* [Janne Mareike Koschinski][justjanne] for providing information on how to get certain information using Go (and the amazing [README][powerline-go])
|
||||
|
||||
[oh-my-posh]: https://github.com/JanDeDobbeleer/oh-my-posh
|
||||
[patreon-badge]: https://img.shields.io/badge/Support-Become%20a%20Patreon!-red.svg
|
||||
[patreon]: https://www.patreon.com/jandedobbeleer
|
||||
[liberapay-badge]: https://img.shields.io/badge/Liberapay-Donate-%23f6c915.svg
|
||||
[liberapay]: https://liberapay.com/jandedobbeleer
|
||||
[kofi-badge]: https://img.shields.io/badge/Ko--fi-Buy%20me%20a%20coffee!-%2346b798.svg
|
||||
[kofi]: https://ko-fi.com/jandedobbeleer
|
||||
[releases]: https://github.com/JanDeDobbeleer/go-my-posh/releases
|
||||
[jandedobbeleer]: https://github.com/JanDeDobbeleer/go-my-posh/blob/master/Themes/jandedobbeleer.json
|
||||
[themes]: https://github.com/JanDeDobbeleer/go-my-posh/tree/master/Themes
|
||||
[chrisbenti-psconfig]: https://github.com/chrisbenti/PS-Config
|
||||
[keithdahlby-poshgit]: https://github.com/dahlbyk/posh-git
|
||||
[oh-my-zsh]: https://github.com/robbyrussell/oh-my-zsh
|
||||
[justjanne]: https://github.com/justjanne
|
||||
[powerline-go]: https://github.com/justjanne/powerline-go
|
77
Themes/agnoster.json
Normal file
77
Themes/agnoster.json
Normal file
|
@ -0,0 +1,77 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "root",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#ffe9aa",
|
||||
"properties": {
|
||||
"root_icon": "襁"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "session",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#ffffff",
|
||||
"properties": {
|
||||
"user_info_separator": "@"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#91ddff",
|
||||
"properties" : {
|
||||
"home_icon": "",
|
||||
"folder_icon": "",
|
||||
"windows_registry_icon": "",
|
||||
"folder_separator_icon": " ",
|
||||
"style": "agnoster"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"foreground": "#193549",
|
||||
"background": "#95ffa4",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "virtualenv",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#906cff",
|
||||
"properties": {
|
||||
"python_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "powerline",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#ff8080",
|
||||
"properties": {
|
||||
"error_icon": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
69
Themes/agnosterplus.json
Normal file
69
Themes/agnosterplus.json
Normal file
|
@ -0,0 +1,69 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "right",
|
||||
"line_offset": -1,
|
||||
"segments": [
|
||||
{
|
||||
"type": "time",
|
||||
"style": "plain",
|
||||
"foreground": "#007ACC",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"time_format": "15:04:05"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line-break"
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "session",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#ffffff",
|
||||
"properties": {
|
||||
"user_info_separator": "@"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#91ddff",
|
||||
"properties" : {
|
||||
"home_icon": "",
|
||||
"folder_icon": "",
|
||||
"windows_registry_icon": "",
|
||||
"folder_separator_icon": " ",
|
||||
"style": "agnoster"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"foreground": "#193549",
|
||||
"background": "#95ffa4",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
62
Themes/aliens.json
Normal file
62
Themes/aliens.json
Normal file
|
@ -0,0 +1,62 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "session",
|
||||
"style": "diamond",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#61AFEF",
|
||||
"leading_diamond": "",
|
||||
"trailing_diamond": "",
|
||||
"properties": {
|
||||
"user_info_separator": "@",
|
||||
"postfix": " "
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#C678DD",
|
||||
"properties": {
|
||||
"home_icon": "~",
|
||||
"style": "short"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"foreground": "#193549",
|
||||
"background": "#95ffa4",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "virtualenv",
|
||||
"style": "diamond",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#FF6471",
|
||||
"leading_diamond": "",
|
||||
"trailing_diamond": "",
|
||||
"properties": {
|
||||
"python_icon": "",
|
||||
"prefix": "<#193549> </>"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
73
Themes/avit.json
Normal file
73
Themes/avit.json
Normal file
|
@ -0,0 +1,73 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"home_icon": "~",
|
||||
"style": "short"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#C2C206",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "root",
|
||||
"style": "plain",
|
||||
"foreground": "#B5B50D",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"root_icon": "⚡"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#C94A16",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": "x"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line-break"
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#007ACC",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": "▶"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
84
Themes/darkblood.json
Normal file
84
Themes/darkblood.json
Normal file
|
@ -0,0 +1,84 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "session",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"user_info_separator": "",
|
||||
"display_computer": false,
|
||||
"prefix": "<#CB4B16>┏[</>",
|
||||
"postfix": "<#CB4B16>]</>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": "",
|
||||
"prefix": "<#CB4B16>[</>",
|
||||
"postfix": "<#CB4B16>]</>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "root",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"root_icon": "⚡",
|
||||
"prefix": "<#CB4B16>[</>",
|
||||
"postfix": "<#CB4B16>]</>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": "x",
|
||||
"prefix": "<#CB4B16>[</>",
|
||||
"postfix": "<#CB4B16>]</>"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line-break"
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"home_icon": "~",
|
||||
"style": "short",
|
||||
"prefix": "<#CB4B16>[</>",
|
||||
"postfix": "<#CB4B16>]></>"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
78
Themes/emodipt.json
Normal file
78
Themes/emodipt.json
Normal file
|
@ -0,0 +1,78 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "time",
|
||||
"style": "plain",
|
||||
"foreground": "#E5C07B",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"time_format": "15:04:05",
|
||||
"prefix": "[ ",
|
||||
"postfix": " ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "root",
|
||||
"style": "plain",
|
||||
"foreground": "#B5B50D",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"root_icon": "⚡"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#61AFEF",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"home_icon": "~",
|
||||
"style": "agnoster",
|
||||
"postfix": " on"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#F3C267",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "🚦 ",
|
||||
"display_status": true,
|
||||
"branch_identical_icon": "✅",
|
||||
"branch_ahead_icon": "",
|
||||
"branch_behind_icon": "",
|
||||
"branch_gone_icon": "❎",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#C94A16",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": "x"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#E06C75",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"prefix": "",
|
||||
"text": " ❯"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
82
Themes/fish.json
Normal file
82
Themes/fish.json
Normal file
|
@ -0,0 +1,82 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": " ",
|
||||
"postfix": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "root",
|
||||
"style": "plain",
|
||||
"foreground": "#100e23",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"root_icon": "襁"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "session",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"user_info_separator": "@"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#007ACC",
|
||||
"properties" : {
|
||||
"home_icon": "~",
|
||||
"folder_icon": "",
|
||||
"windows_registry_icon": "",
|
||||
"folder_separator_icon": "",
|
||||
"style": "short",
|
||||
"prefix": "<#193549></> ",
|
||||
"postfix": " "
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#007ACC",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": "",
|
||||
"prefix": "<#ffffff></> ",
|
||||
"postfix": " "
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#007ACC",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"prefix": "",
|
||||
"text": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549"
|
||||
}
|
114
Themes/honukai.json
Normal file
114
Themes/honukai.json
Normal file
|
@ -0,0 +1,114 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "session",
|
||||
"style": "plain",
|
||||
"foreground": "#FFFFFF",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"user_info_separator": " <#ffffff>in</> ",
|
||||
"prefix": "<#0377C8># </>",
|
||||
"user_color": "#0377C8",
|
||||
"computer_color": "#4A9207"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#0973C0",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"home_icon": "~",
|
||||
"folder_icon": "",
|
||||
"windows_registry_icon": "",
|
||||
"folder_separator_icon": "",
|
||||
"style": "short"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#B8B80A",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": "",
|
||||
"prefix": "<#ffffff>on git:</>"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "right",
|
||||
"segments": [
|
||||
{
|
||||
"type": "time",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"prefix": "[",
|
||||
"postfix": "]"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line-break"
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "root",
|
||||
"style": "plain",
|
||||
"foreground": "#CECE04",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"root_icon": "襁"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "virtualenv",
|
||||
"style": "plain",
|
||||
"foreground": "#100e23",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"python_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#CB4B16",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#CC4B16",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": "→"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
94
Themes/jandedobbeleer.json
Normal file
94
Themes/jandedobbeleer.json
Normal file
|
@ -0,0 +1,94 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "session",
|
||||
"style": "diamond",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#ffb300",
|
||||
"leading_diamond": "",
|
||||
"trailing_diamond": "",
|
||||
"properties": {
|
||||
"user_info_separator": "@",
|
||||
"postfix": " "
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "spotify",
|
||||
"style": "powerline",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#1BD760",
|
||||
"properties": {
|
||||
"prefix": " ",
|
||||
"paused_icon": " ",
|
||||
"playing_icon": " "
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#61AFEF",
|
||||
"properties": {
|
||||
"prefix": " ",
|
||||
"style": "folder"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"foreground": "#193549",
|
||||
"background": "#ffeb3b",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "battery",
|
||||
"style": "powerline",
|
||||
"foreground": "#193549",
|
||||
"background": "#ffeb3b",
|
||||
"properties": {
|
||||
"battery_icon": "",
|
||||
"discharging_icon": " ",
|
||||
"charging_icon": " ",
|
||||
"charged_icon": " ",
|
||||
"color_background": true,
|
||||
"charged_color": "#4caf50",
|
||||
"charging_color": "#40c4ff",
|
||||
"discharging_color": "#ff5722",
|
||||
"postfix": "% "
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "diamond",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#00897b",
|
||||
"leading_diamond": "",
|
||||
"trailing_diamond": "",
|
||||
"properties": {
|
||||
"error_icon": "",
|
||||
"display_error_code": false,
|
||||
"always_enabled": true,
|
||||
"error_color": "#e91e63",
|
||||
"color_background": true,
|
||||
"prefix": "<#193549> </>"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
46
Themes/lambda.json
Normal file
46
Themes/lambda.json
Normal file
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#F5F5F5",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": "ﬦ"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#B80101",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"style": "agnoster"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#B80101",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": "",
|
||||
"prefix": " <#F5F5F5>git:</>"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
61
Themes/material.json
Normal file
61
Themes/material.json
Normal file
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": "<#C591E8>❭</><#69FF94>❭</>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#56B6C2",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"style": "folder"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#D0666F",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"display_status": false,
|
||||
"prefix": "<#5FAAE8>git:(</>",
|
||||
"postfix": "<#5FAAE8>)</>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#DCB977",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": "✗",
|
||||
"display_error_code": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "time",
|
||||
"style": "plain",
|
||||
"foreground": "#66F68F",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"time_format": "15:04"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
95
Themes/paradox.json
Normal file
95
Themes/paradox.json
Normal file
|
@ -0,0 +1,95 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "root",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#ffe9aa",
|
||||
"properties": {
|
||||
"root_icon": "襁"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "session",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#ffffff",
|
||||
"properties": {
|
||||
"user_info_separator": "@"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#91ddff",
|
||||
"properties": {
|
||||
"home_icon": "~",
|
||||
"folder_icon": "",
|
||||
"windows_registry_icon": "",
|
||||
"folder_separator_icon": "",
|
||||
"style": "short"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"foreground": "#193549",
|
||||
"background": "#95ffa4",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "virtualenv",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#906cff",
|
||||
"properties": {
|
||||
"python_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "powerline",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#ff8080",
|
||||
"properties": {
|
||||
"error_icon": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line-break"
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#007ACC",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
86
Themes/pararussel.json
Normal file
86
Themes/pararussel.json
Normal file
|
@ -0,0 +1,86 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": "<#C591E8>❭</><#69FF94>❭</>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#56B6C2",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"style": "folder"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#D0666F",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"display_status": false,
|
||||
"prefix": "<#5FAAE8>git:(</>",
|
||||
"postfix": "<#5FAAE8>)</>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#DCB977",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": "✗",
|
||||
"display_error_code": false
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "right",
|
||||
"segments": [
|
||||
{
|
||||
"type": "command",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"shell": "bash",
|
||||
"command": "git log --pretty=format:%cr -1 || date +%H:%m:%S"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line-break"
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": " "
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
107
Themes/powerlevel10k_classic.json
Normal file
107
Themes/powerlevel10k_classic.json
Normal file
|
@ -0,0 +1,107 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#26C6DA",
|
||||
"background": "#546E7A",
|
||||
"properties": {
|
||||
"text": "",
|
||||
"postfix": " "
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "root",
|
||||
"style": "plain",
|
||||
"foreground": "#26C6DA",
|
||||
"background": "#546E7A",
|
||||
"properties": {
|
||||
"root_icon": "襁"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#26C6DA",
|
||||
"background": "#546E7A",
|
||||
"properties": {
|
||||
"home_icon": "~",
|
||||
"style": "short",
|
||||
"postfix": " "
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "diamond",
|
||||
"foreground": "#D4E157",
|
||||
"background": "#546E7A",
|
||||
"trailing_diamond": "",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": "",
|
||||
"prefix": "<#26C6DA> </>"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "right",
|
||||
"segments": [
|
||||
{
|
||||
"type": "session",
|
||||
"style": "diamond",
|
||||
"foreground": "#D4E157",
|
||||
"background": "#546E7A",
|
||||
"leading_diamond": "",
|
||||
"properties": {
|
||||
"user_info_separator": "@",
|
||||
"postfix": " <#26C6DA></> "
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "time",
|
||||
"style": "plain",
|
||||
"foreground": "#D4E157",
|
||||
"background": "#546E7A",
|
||||
"properties": {
|
||||
"time_format": "15:04:05",
|
||||
"postfix": " "
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "newline"
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#D4E157",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": "❯",
|
||||
"always_enabled": true,
|
||||
"error_color": "#FF5252",
|
||||
"display_error_code": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
66
Themes/powerlevel10k_lean.json
Normal file
66
Themes/powerlevel10k_lean.json
Normal file
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "right",
|
||||
"line_offset": -1,
|
||||
"segments": [
|
||||
{
|
||||
"type": "time",
|
||||
"style": "plain",
|
||||
"foreground": "#00C5C7",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"time_format": "15:04:05"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line-break"
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#77E4F7",
|
||||
"background": "#193549",
|
||||
"properties" : {
|
||||
"home_icon": "~",
|
||||
"style": "short"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#FFE700",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#43D426",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": "❯"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
74
Themes/powerline.json
Normal file
74
Themes/powerline.json
Normal file
|
@ -0,0 +1,74 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"powerline_separator": "",
|
||||
"segments": [
|
||||
{
|
||||
"type": "root",
|
||||
"style": "plain",
|
||||
"foreground": "#FFEE58",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"root_icon": "襁"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "session",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"user_info_separator": "@"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#91ddff",
|
||||
"properties" : {
|
||||
"home_icon": "~",
|
||||
"style": "short"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "powerline",
|
||||
"foreground": "#193549",
|
||||
"background": "#95ffa4",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "virtualenv",
|
||||
"style": "powerline",
|
||||
"foreground": "#100e23",
|
||||
"background": "#906cff",
|
||||
"properties": {
|
||||
"python_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "powerline",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#ff8080",
|
||||
"properties": {
|
||||
"error_icon": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
52
Themes/robbyrussel.json
Normal file
52
Themes/robbyrussel.json
Normal file
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#98C379",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": "→"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#56B6C2",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"style": "folder"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#D0666F",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"display_status": false,
|
||||
"prefix": "<#5FAAE8>git:(</>",
|
||||
"postfix": "<#5FAAE8>)</>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#DCB977",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": "✗",
|
||||
"display_error_code": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
86
Themes/sorin.json
Normal file
86
Themes/sorin.json
Normal file
|
@ -0,0 +1,86 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#CB4B16",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "root",
|
||||
"style": "plain",
|
||||
"foreground": "#CECE04",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"root_icon": "襁"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "session",
|
||||
"style": "plain",
|
||||
"foreground": "#FFFFFF",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"user_info_separator": "@"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#0973C0",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"home_icon": "",
|
||||
"folder_icon": "",
|
||||
"windows_registry_icon": "",
|
||||
"folder_separator_icon": " ",
|
||||
"style": "agnoster"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#C1C106",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"branch_identical_icon": "≡",
|
||||
"branch_ahead_icon": "↑",
|
||||
"branch_behind_icon": "↓",
|
||||
"branch_gone_icon": "≢",
|
||||
"local_working_icon": "",
|
||||
"local_staged_icon": "",
|
||||
"prefix": "<#ffffff>git:</>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "virtualenv",
|
||||
"style": "plain",
|
||||
"foreground": "#100e23",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"python_icon": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": "<#CB4B16>❭</><#CACA02>❭</><#4E9A06>❭</>"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
80
Themes/star.json
Normal file
80
Themes/star.json
Normal file
|
@ -0,0 +1,80 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"home_icon": "~",
|
||||
"style": "short",
|
||||
"postfix": " on"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#F3C267",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"display_status": false,
|
||||
"postfix": " <#C49EE9>[?!]</>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"style": "plain",
|
||||
"foreground": "#C49EE9",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"shell": "bash",
|
||||
"command": "find . -name package.json -depth 1 -exec echo \" <#ffffff>via node</>\" \\;"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "root",
|
||||
"style": "plain",
|
||||
"foreground": "#B5B50D",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"root_icon": "⚡"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#C94A16",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": "x"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "line-break"
|
||||
},
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#63F08C",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": "→"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
66
Themes/zash.json
Normal file
66
Themes/zash.json
Normal file
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "prompt",
|
||||
"alignment": "left",
|
||||
"segments": [
|
||||
{
|
||||
"type": "session",
|
||||
"style": "plain",
|
||||
"foreground": "#E36464",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"user_info_separator": "",
|
||||
"display_computer": false,
|
||||
"prefix": "@"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"style": "plain",
|
||||
"foreground": "#62ED8B",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"text": "→",
|
||||
"postfix": "",
|
||||
"prefix": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"style": "plain",
|
||||
"foreground": "#56B6C2",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"style": "folder",
|
||||
"postfix": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"style": "plain",
|
||||
"foreground": "#D4AAFC",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"branch_icon": "",
|
||||
"display_status": false,
|
||||
"prefix": " <#DDB15F>git(</>",
|
||||
"postfix": "<#DDB15F>)</>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "exit",
|
||||
"style": "plain",
|
||||
"foreground": "#DCB977",
|
||||
"background": "#193549",
|
||||
"properties": {
|
||||
"error_icon": "✗",
|
||||
"display_error_code": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"console_background_color": "#193549",
|
||||
"end_space_enabled": true
|
||||
}
|
35
appveyor.yml
Normal file
35
appveyor.yml
Normal file
|
@ -0,0 +1,35 @@
|
|||
skip_tags: true
|
||||
skip_commits:
|
||||
files:
|
||||
- .github/*
|
||||
- README.md
|
||||
- CHANGELOG.md
|
||||
environment:
|
||||
GH_KEY:
|
||||
secure: Vd8UVmtAfMZGW0OzImzMpG3ZfBoK6xOhduxnTJwyi5DmgbMuUz84SZ7AKke8xHsJ
|
||||
image:
|
||||
- Visual Studio 2019
|
||||
- Ubuntu
|
||||
build_script:
|
||||
- pwsh: (Get-Content '.\oh-my-posh.psd1' -Raw).Replace('1.0.0.0', $ENV:APPVEYOR_BUILD_VERSION) | Out-File -Encoding 'UTF8' '.\oh-my-posh.psd1'
|
||||
before_test:
|
||||
- pwsh: .\Build\setup_test_env.ps1
|
||||
test_script:
|
||||
- pwsh: >-
|
||||
if ($isWindows) {
|
||||
.\Build\test_windows.ps1
|
||||
}
|
||||
else {
|
||||
Invoke-Pester
|
||||
}
|
||||
deploy_script:
|
||||
- pwsh: >-
|
||||
if ($isWindows) {
|
||||
.\Build\release.ps1
|
||||
}
|
||||
on_success:
|
||||
- git config --global credential.helper store
|
||||
- ps: Add-Content -Path "$HOME\.git-credentials" -Value "https://$($env:GH_KEY):x-oauth-basic@github.com`n" -NoNewline
|
||||
- git config --global user.email "Your email"
|
||||
- git config --global user.name "Your Name"
|
||||
- git push
|
49
color_writer.go
Executable file
49
color_writer.go
Executable file
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/gookit/color.v1"
|
||||
)
|
||||
|
||||
//ColorWriter writes colorized strings
|
||||
type ColorWriter struct {
|
||||
Buffer *bytes.Buffer
|
||||
}
|
||||
|
||||
func (w *ColorWriter) writeColoredText(background string, foreground string, text string) {
|
||||
style := color.HEXStyle(foreground, background)
|
||||
text = style.Sprint(text)
|
||||
w.Buffer.WriteString(text)
|
||||
}
|
||||
|
||||
func (w *ColorWriter) writeAndRemoveText(background string, foreground string, text string, textToRemove string, parentText string) string {
|
||||
w.writeColoredText(background, foreground, text)
|
||||
return strings.Replace(parentText, textToRemove, "", 1)
|
||||
}
|
||||
|
||||
func (w *ColorWriter) write(background string, foreground string, text string) {
|
||||
style := color.HEXStyle(foreground, background)
|
||||
text = style.Sprint(text)
|
||||
|
||||
r := regexp.MustCompile(`<\s*(?P<color>#[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})>(?P<text>.*?)<\s*/\s*>`)
|
||||
match := r.FindAllStringSubmatch(text, -1)
|
||||
for i := range match {
|
||||
// get the text before the color override and write that first
|
||||
textBeforeColorOverride := strings.Split(text, match[i][0])[0]
|
||||
text = w.writeAndRemoveText(background, foreground, textBeforeColorOverride, textBeforeColorOverride, text)
|
||||
text = w.writeAndRemoveText(background, match[i][1], match[i][2], match[i][0], text)
|
||||
}
|
||||
// color the remaining part of text with background and foreground
|
||||
w.writeColoredText(background, foreground, text)
|
||||
}
|
||||
|
||||
func (w *ColorWriter) string() string {
|
||||
return w.Buffer.String()
|
||||
}
|
||||
|
||||
func (w *ColorWriter) reset() {
|
||||
w.Buffer.Reset()
|
||||
}
|
46
color_writer_test.go
Executable file
46
color_writer_test.go
Executable file
|
@ -0,0 +1,46 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWriteAndRemoveText(t *testing.T) {
|
||||
writer := &ColorWriter{
|
||||
Buffer: new(bytes.Buffer),
|
||||
}
|
||||
inputText := "This is white, <#ff5733>this is orange</>, white again"
|
||||
text := writer.writeAndRemoveText("#193549", "#fff", "This is white, ", "This is white, ", inputText)
|
||||
assert.Equal(t, "This is white, ", writer.string())
|
||||
assert.Equal(t, "<#ff5733>this is orange</>, white again", text)
|
||||
}
|
||||
|
||||
func TestWriteAndRemoveTextColored(t *testing.T) {
|
||||
writer := &ColorWriter{
|
||||
Buffer: new(bytes.Buffer),
|
||||
}
|
||||
inputText := "This is white, <#ff5733>this is orange</>, white again"
|
||||
text := writer.writeAndRemoveText("#193549", "#ff5733", "this is orange", "<#ff5733>this is orange</>", inputText)
|
||||
assert.Equal(t, "this is orange", writer.string())
|
||||
assert.Equal(t, "This is white, , white again", text)
|
||||
}
|
||||
|
||||
func TestWritePlain(t *testing.T) {
|
||||
writer := &ColorWriter{
|
||||
Buffer: new(bytes.Buffer),
|
||||
}
|
||||
text := "This is white, this is orange, white again"
|
||||
writer.write("#193549", "#ff5733", text)
|
||||
assert.Equal(t, "This is white, this is orange, white again", writer.string())
|
||||
}
|
||||
|
||||
func TestWriteColorOverride(t *testing.T) {
|
||||
writer := &ColorWriter{
|
||||
Buffer: new(bytes.Buffer),
|
||||
}
|
||||
text := "This is white, <#ff5733>this is orange</>, white again"
|
||||
writer.write("#193549", "#ff5733", text)
|
||||
assert.Equal(t, "This is white, this is orange, white again", writer.string())
|
||||
}
|
159
engine.go
Normal file
159
engine.go
Normal file
|
@ -0,0 +1,159 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"golang.org/x/text/unicode/norm"
|
||||
)
|
||||
|
||||
type engine struct {
|
||||
settings *Settings
|
||||
env environmentInfo
|
||||
renderer *ColorWriter
|
||||
activeBlock *Block
|
||||
activeSegment *Segment
|
||||
previousActiveSegment *Segment
|
||||
}
|
||||
|
||||
func (e *engine) getPowerlineColor(foreground bool) string {
|
||||
if e.previousActiveSegment == nil {
|
||||
return e.settings.ConsoleBackgroundColor
|
||||
}
|
||||
if !foreground && e.activeSegment.Style != Powerline {
|
||||
return e.settings.ConsoleBackgroundColor
|
||||
}
|
||||
if foreground && e.previousActiveSegment.Style != Powerline {
|
||||
return e.settings.ConsoleBackgroundColor
|
||||
}
|
||||
return e.previousActiveSegment.Background
|
||||
}
|
||||
|
||||
func (e *engine) writePowerLineSeparator(background string, foreground string) {
|
||||
if e.activeBlock.InvertPowerlineSeparatorColor {
|
||||
e.renderer.write(foreground, background, e.activeBlock.PowerlineSeparator)
|
||||
return
|
||||
}
|
||||
e.renderer.write(background, foreground, e.activeBlock.PowerlineSeparator)
|
||||
}
|
||||
|
||||
func (e *engine) endPowerline() {
|
||||
if e.activeSegment != nil &&
|
||||
e.activeSegment.Style != Powerline &&
|
||||
e.previousActiveSegment != nil &&
|
||||
e.previousActiveSegment.Style == Powerline {
|
||||
e.writePowerLineSeparator(e.getPowerlineColor(false), e.previousActiveSegment.Background)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *engine) renderPowerLineSegment(text string) {
|
||||
e.writePowerLineSeparator(e.activeSegment.Background, e.getPowerlineColor(true))
|
||||
e.renderText(text)
|
||||
}
|
||||
|
||||
func (e *engine) renderPlainSegment(text string) {
|
||||
e.renderText(text)
|
||||
}
|
||||
|
||||
func (e *engine) renderDiamondSegment(text string) {
|
||||
e.renderer.write(e.settings.ConsoleBackgroundColor, e.activeSegment.Background, e.activeSegment.LeadingDiamond)
|
||||
e.renderText(text)
|
||||
e.renderer.write(e.settings.ConsoleBackgroundColor, e.activeSegment.Background, e.activeSegment.TrailingDiamond)
|
||||
}
|
||||
|
||||
func (e *engine) getStringProperty(property Property, defaultValue string) string {
|
||||
if value, ok := e.activeSegment.Properties[property]; ok {
|
||||
return parseString(value, defaultValue)
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func (e *engine) renderText(text string) {
|
||||
prefix := e.getStringProperty(Prefix, " ")
|
||||
postfix := e.getStringProperty(Postfix, " ")
|
||||
e.renderer.write(e.activeSegment.Background, e.activeSegment.Foreground, fmt.Sprintf("%s%s%s", prefix, text, postfix))
|
||||
}
|
||||
|
||||
func (e *engine) renderSegmentText(text string) {
|
||||
switch e.activeSegment.Style {
|
||||
case Plain:
|
||||
e.renderPlainSegment(text)
|
||||
case Diamond:
|
||||
e.renderDiamondSegment(text)
|
||||
default:
|
||||
e.renderPowerLineSegment(text)
|
||||
}
|
||||
e.previousActiveSegment = e.activeSegment
|
||||
}
|
||||
|
||||
func (e *engine) renderBlockSegments(block *Block) string {
|
||||
defer e.reset()
|
||||
e.activeBlock = block
|
||||
for _, segment := range block.Segments {
|
||||
props := segment.mapSegmentWithWriter(e.env)
|
||||
if !segment.enabled() {
|
||||
continue
|
||||
}
|
||||
e.activeSegment = segment
|
||||
e.endPowerline()
|
||||
text := segment.string()
|
||||
e.activeSegment.Background = props.background
|
||||
e.activeSegment.Foreground = props.foreground
|
||||
e.renderSegmentText(text)
|
||||
}
|
||||
if e.previousActiveSegment != nil && e.previousActiveSegment.Style == Powerline {
|
||||
e.writePowerLineSeparator(e.settings.ConsoleBackgroundColor, e.previousActiveSegment.Background)
|
||||
}
|
||||
return e.renderer.string()
|
||||
}
|
||||
|
||||
func (e *engine) lenWithoutANSI(str string) int {
|
||||
ansi := "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
|
||||
re := regexp.MustCompile(ansi)
|
||||
stripped := re.ReplaceAllString(str, "")
|
||||
var i norm.Iter
|
||||
i.InitString(norm.NFD, stripped)
|
||||
var count int
|
||||
for !i.Done() {
|
||||
i.Next()
|
||||
count++
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func (e *engine) string() string {
|
||||
var buffer bytes.Buffer
|
||||
defer buffer.Reset()
|
||||
for _, block := range e.settings.Blocks {
|
||||
// if line break, append a line break
|
||||
if block.Type == LineBreak {
|
||||
buffer.WriteString("\n")
|
||||
continue
|
||||
}
|
||||
if block.LineOffset < 0 {
|
||||
buffer.WriteString(fmt.Sprintf("\x1b[%dF", -block.LineOffset))
|
||||
} else if block.LineOffset > 0 {
|
||||
buffer.WriteString(fmt.Sprintf("\x1b[%dE", block.LineOffset))
|
||||
}
|
||||
switch block.Alignment {
|
||||
case Right:
|
||||
buffer.WriteString(fmt.Sprintf("\x1b[%dC", 1000))
|
||||
blockText := e.renderBlockSegments(block)
|
||||
buffer.WriteString(fmt.Sprintf("\x1b[%dD", e.lenWithoutANSI(blockText)+e.settings.RightSegmentOffset))
|
||||
buffer.WriteString(blockText)
|
||||
default:
|
||||
buffer.WriteString(e.renderBlockSegments(block))
|
||||
}
|
||||
}
|
||||
if e.settings.EndSpaceEnabled {
|
||||
buffer.WriteString(" ")
|
||||
}
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
func (e *engine) reset() {
|
||||
e.renderer.reset()
|
||||
e.previousActiveSegment = nil
|
||||
e.activeBlock = nil
|
||||
}
|
31
engine_test.go
Executable file
31
engine_test.go
Executable file
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLenWithoutANSI(t *testing.T) {
|
||||
block := &Block{
|
||||
Type: Prompt,
|
||||
Alignment: Right,
|
||||
Segments: []*Segment{
|
||||
{
|
||||
Type: Time,
|
||||
Style: Plain,
|
||||
Background: "#B8B80A",
|
||||
Foreground: "#ffffff",
|
||||
},
|
||||
},
|
||||
}
|
||||
engine := &engine{
|
||||
renderer: &ColorWriter{
|
||||
Buffer: new(bytes.Buffer),
|
||||
},
|
||||
}
|
||||
blockText := engine.renderBlockSegments(block)
|
||||
strippedLength := engine.lenWithoutANSI(blockText)
|
||||
assert.Equal(t, 10, strippedLength)
|
||||
}
|
105
environment.go
Executable file
105
environment.go
Executable file
|
@ -0,0 +1,105 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/distatus/battery"
|
||||
)
|
||||
|
||||
type environmentInfo interface {
|
||||
getenv(key string) string
|
||||
getwd() (string, error)
|
||||
getPathSeperator() string
|
||||
getCurrentUser() (*user.User, error)
|
||||
isRunningAsRoot() bool
|
||||
getHostName() (string, error)
|
||||
getRuntimeGOOS() string
|
||||
hasCommand(command string) bool
|
||||
runCommand(command string, args ...string) string
|
||||
runShellCommand(shell string, command string) string
|
||||
lastErrorCode() int
|
||||
getArgs() *args
|
||||
getBatteryInfo() (*battery.Battery, error)
|
||||
}
|
||||
|
||||
type environment struct {
|
||||
args *args
|
||||
}
|
||||
|
||||
func (env *environment) getenv(key string) string {
|
||||
return os.Getenv(key)
|
||||
}
|
||||
|
||||
func (env *environment) getwd() (string, error) {
|
||||
return os.Getwd()
|
||||
}
|
||||
|
||||
func (env *environment) getPathSeperator() string {
|
||||
return string(os.PathSeparator)
|
||||
}
|
||||
|
||||
func (env *environment) getCurrentUser() (*user.User, error) {
|
||||
return user.Current()
|
||||
}
|
||||
|
||||
func (env *environment) getHostName() (string, error) {
|
||||
hostName, err := os.Hostname()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return cleanHostName(hostName), nil
|
||||
}
|
||||
|
||||
func (env *environment) getRuntimeGOOS() string {
|
||||
return runtime.GOOS
|
||||
}
|
||||
|
||||
func (env *environment) runCommand(command string, args ...string) string {
|
||||
out, err := exec.Command(command, args...).Output()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(out))
|
||||
}
|
||||
|
||||
func (env *environment) runShellCommand(shell string, command string) string {
|
||||
out, err := exec.Command(shell, "-c", command).Output()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(out))
|
||||
}
|
||||
|
||||
func (env *environment) hasCommand(command string) bool {
|
||||
_, err := exec.LookPath(command)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (env *environment) lastErrorCode() int {
|
||||
return *env.args.ErrorCode
|
||||
}
|
||||
|
||||
func (env *environment) getArgs() *args {
|
||||
return env.args
|
||||
}
|
||||
|
||||
func (env *environment) getBatteryInfo() (*battery.Battery, error) {
|
||||
return battery.Get(0)
|
||||
}
|
||||
|
||||
func cleanHostName(hostName string) string {
|
||||
garbage := []string{
|
||||
".lan",
|
||||
".local",
|
||||
}
|
||||
for _, g := range garbage {
|
||||
hostName = strings.Replace(hostName, g, "", 1)
|
||||
}
|
||||
return hostName
|
||||
}
|
23
environment_test.go
Normal file
23
environment_test.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNormalHostName(t *testing.T) {
|
||||
hostName := "hello"
|
||||
assert.Equal(t, hostName, cleanHostName(hostName))
|
||||
}
|
||||
|
||||
func TestHostNameWithLocal(t *testing.T) {
|
||||
hostName := "hello.local"
|
||||
assert.Equal(t, "hello", cleanHostName(hostName))
|
||||
}
|
||||
|
||||
func TestHostNameWithLan(t *testing.T) {
|
||||
hostName := "hello.lan"
|
||||
cleanHostName := cleanHostName(hostName)
|
||||
assert.Equal(t, "hello", cleanHostName)
|
||||
}
|
11
environment_unix.go
Executable file
11
environment_unix.go
Executable file
|
@ -0,0 +1,11 @@
|
|||
// +build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func (env *environment) isRunningAsRoot() bool {
|
||||
return os.Geteuid() == 0
|
||||
}
|
36
environment_windows.go
Executable file
36
environment_windows.go
Executable file
|
@ -0,0 +1,36 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func (env *environment) isRunningAsRoot() bool {
|
||||
var sid *windows.SID
|
||||
// Although this looks scary, it is directly copied from the
|
||||
// official windows documentation. The Go API for this is a
|
||||
// direct wrap around the official C++ API.
|
||||
// See https://docs.microsoft.com/en-us/windows/desktop/api/securitybaseapi/nf-securitybaseapi-checktokenmembership
|
||||
err := windows.AllocateAndInitializeSid(
|
||||
&windows.SECURITY_NT_AUTHORITY,
|
||||
2,
|
||||
windows.SECURITY_BUILTIN_DOMAIN_RID,
|
||||
windows.DOMAIN_ALIAS_RID_ADMINS,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
&sid)
|
||||
if err != nil {
|
||||
log.Fatalf("SID Error: %s", err)
|
||||
return false
|
||||
}
|
||||
|
||||
// This appears to cast a null pointer so I'm not sure why this
|
||||
// works, but this guy says it does and it Works for Me™:
|
||||
// https://github.com/golang/go/issues/28804#issuecomment-438838144
|
||||
token := windows.Token(0)
|
||||
member, err := token.IsMember(sid)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return member && token.IsElevated()
|
||||
}
|
50
main.go
Executable file
50
main.go
Executable file
|
@ -0,0 +1,50 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type args struct {
|
||||
ErrorCode *int
|
||||
PrintConfig *bool
|
||||
Config *string
|
||||
}
|
||||
|
||||
func main() {
|
||||
args := &args{
|
||||
ErrorCode: flag.Int(
|
||||
"error",
|
||||
0,
|
||||
"Error code of previously executed command"),
|
||||
PrintConfig: flag.Bool(
|
||||
"print-config",
|
||||
false,
|
||||
"Config prints the current settings in json format"),
|
||||
Config: flag.String(
|
||||
"config",
|
||||
"",
|
||||
"Add the path to a configuration you wish to load"),
|
||||
}
|
||||
flag.Parse()
|
||||
env := &environment{
|
||||
args: args,
|
||||
}
|
||||
settings := GetSettings(env)
|
||||
if *args.PrintConfig {
|
||||
theme, _ := json.MarshalIndent(settings, "", " ")
|
||||
fmt.Println(string(theme))
|
||||
return
|
||||
}
|
||||
engine := &engine{
|
||||
settings: settings,
|
||||
env: env,
|
||||
renderer: &ColorWriter{
|
||||
Buffer: new(bytes.Buffer),
|
||||
},
|
||||
}
|
||||
prompt := engine.string()
|
||||
fmt.Print(prompt)
|
||||
}
|
75
properties.go
Normal file
75
properties.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
package main
|
||||
|
||||
import "regexp"
|
||||
|
||||
//Property defines one property of a segment for context
|
||||
type Property string
|
||||
|
||||
//general Properties used across Segments
|
||||
const (
|
||||
//Style indicates with style to use
|
||||
Style Property = "style"
|
||||
//Prefix adds a text prefix to the segment
|
||||
Prefix Property = "prefix"
|
||||
//Postfix adds a text postfix to the segment
|
||||
Postfix Property = "postfix"
|
||||
//ColorBackground color the background or foreground when a specific color is set
|
||||
ColorBackground Property = "color_background"
|
||||
)
|
||||
|
||||
type properties struct {
|
||||
values map[Property]interface{}
|
||||
foreground string
|
||||
background string
|
||||
}
|
||||
|
||||
func (p *properties) getString(property Property, defaultValue string) string {
|
||||
if p == nil || p.values == nil {
|
||||
return defaultValue
|
||||
}
|
||||
val, found := p.values[property]
|
||||
if !found {
|
||||
return defaultValue
|
||||
}
|
||||
return parseString(val, defaultValue)
|
||||
}
|
||||
|
||||
func parseString(value interface{}, defaultValue string) string {
|
||||
stringValue, ok := value.(string)
|
||||
if !ok {
|
||||
return defaultValue
|
||||
}
|
||||
return stringValue
|
||||
}
|
||||
|
||||
func (p *properties) getColor(property Property, defaultValue string) string {
|
||||
if p == nil || p.values == nil {
|
||||
return defaultValue
|
||||
}
|
||||
val, found := p.values[property]
|
||||
if !found {
|
||||
return defaultValue
|
||||
}
|
||||
colorString := parseString(val, defaultValue)
|
||||
r := regexp.MustCompile(`(?P<color>#[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})`)
|
||||
match := r.FindStringSubmatch(colorString)
|
||||
if match != nil && match[0] != "" {
|
||||
return match[0]
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func (p *properties) getBool(property Property, defaultValue bool) bool {
|
||||
if p == nil || p.values == nil {
|
||||
return defaultValue
|
||||
}
|
||||
val, found := p.values[property]
|
||||
if !found {
|
||||
return defaultValue
|
||||
}
|
||||
boolValue, ok := val.(bool)
|
||||
if !ok {
|
||||
return defaultValue
|
||||
}
|
||||
return boolValue
|
||||
}
|
95
properties_test.go
Normal file
95
properties_test.go
Normal file
|
@ -0,0 +1,95 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetString(t *testing.T) {
|
||||
expected := "expected"
|
||||
values := map[Property]interface{}{TextProperty: expected}
|
||||
properties := properties{
|
||||
values: values,
|
||||
}
|
||||
value := properties.getString(TextProperty, "err")
|
||||
assert.Equal(t, value, expected)
|
||||
}
|
||||
|
||||
func TestGetStringNoEntry(t *testing.T) {
|
||||
expected := "expected"
|
||||
values := map[Property]interface{}{}
|
||||
properties := properties{
|
||||
values: values,
|
||||
}
|
||||
value := properties.getString(TextProperty, expected)
|
||||
assert.Equal(t, value, expected)
|
||||
}
|
||||
|
||||
func TestGetStringNoTextEntry(t *testing.T) {
|
||||
expected := "expected"
|
||||
values := map[Property]interface{}{TextProperty: true}
|
||||
properties := properties{
|
||||
values: values,
|
||||
}
|
||||
value := properties.getString(TextProperty, expected)
|
||||
assert.Equal(t, value, expected)
|
||||
}
|
||||
|
||||
func TestGetColor(t *testing.T) {
|
||||
expected := "#123456"
|
||||
values := map[Property]interface{}{UserColor: expected}
|
||||
properties := properties{
|
||||
values: values,
|
||||
}
|
||||
value := properties.getColor(UserColor, "#789123")
|
||||
assert.Equal(t, value, expected)
|
||||
}
|
||||
|
||||
func TestDefaultColorWithInvalidColorCode(t *testing.T) {
|
||||
expected := "#123456"
|
||||
values := map[Property]interface{}{UserColor: "invalid"}
|
||||
properties := properties{
|
||||
values: values,
|
||||
}
|
||||
value := properties.getColor(UserColor, expected)
|
||||
assert.Equal(t, value, expected)
|
||||
}
|
||||
|
||||
func TestDefaultColorWithUnavailableProperty(t *testing.T) {
|
||||
expected := "#123456"
|
||||
values := map[Property]interface{}{}
|
||||
properties := properties{
|
||||
values: values,
|
||||
}
|
||||
value := properties.getColor(UserColor, expected)
|
||||
assert.Equal(t, value, expected)
|
||||
}
|
||||
|
||||
func TestGetBool(t *testing.T) {
|
||||
expected := true
|
||||
values := map[Property]interface{}{DisplayComputer: expected}
|
||||
properties := properties{
|
||||
values: values,
|
||||
}
|
||||
value := properties.getBool(DisplayComputer, false)
|
||||
assert.True(t, value)
|
||||
}
|
||||
|
||||
func TestGetBoolPropertyNotInMap(t *testing.T) {
|
||||
values := map[Property]interface{}{}
|
||||
properties := properties{
|
||||
values: values,
|
||||
}
|
||||
value := properties.getBool(DisplayComputer, false)
|
||||
assert.False(t, value)
|
||||
}
|
||||
|
||||
func TestGetBoolInvalidProperty(t *testing.T) {
|
||||
values := map[Property]interface{}{DisplayComputer: "borked"}
|
||||
properties := properties{
|
||||
values: values,
|
||||
}
|
||||
value := properties.getBool(DisplayComputer, false)
|
||||
assert.False(t, value)
|
||||
}
|
92
segment.go
Normal file
92
segment.go
Normal file
|
@ -0,0 +1,92 @@
|
|||
package main
|
||||
|
||||
//Segment represent a single segment and it's configuration
|
||||
type Segment struct {
|
||||
Type SegmentType `json:"type"`
|
||||
Style SegmentStyle `json:"style"`
|
||||
Foreground string `json:"foreground"`
|
||||
Background string `json:"background"`
|
||||
LeadingDiamond string `json:"leading_diamond"`
|
||||
TrailingDiamond string `json:"trailing_diamond"`
|
||||
Properties map[Property]interface{} `json:"properties"`
|
||||
writer SegmentWriter
|
||||
}
|
||||
|
||||
//SegmentWriter is the interface used to define what and if to write to the prompt
|
||||
type SegmentWriter interface {
|
||||
enabled() bool
|
||||
string() string
|
||||
init(props *properties, env environmentInfo)
|
||||
}
|
||||
|
||||
//SegmentStyle the syle of segment, for more information, see the constants
|
||||
type SegmentStyle string
|
||||
|
||||
//SegmentType the type of segment, for more information, see the constants
|
||||
type SegmentType string
|
||||
|
||||
const (
|
||||
//Session represents the user info segment
|
||||
Session SegmentType = "session"
|
||||
//Path represents the current path segment
|
||||
Path SegmentType = "path"
|
||||
//Git represents the git status and information
|
||||
Git SegmentType = "git"
|
||||
//Exit writes the last exit code
|
||||
Exit SegmentType = "exit"
|
||||
//Venv writes the virtual env name
|
||||
Venv SegmentType = "virtualenv"
|
||||
//Root writes root symbol
|
||||
Root SegmentType = "root"
|
||||
//Time writes the current timestamp
|
||||
Time SegmentType = "time"
|
||||
//Text writes a text
|
||||
Text SegmentType = "text"
|
||||
//Cmd writes the output of a shell command
|
||||
Cmd SegmentType = "command"
|
||||
//Battery writes the battery percentage
|
||||
Battery SegmentType = "battery"
|
||||
//Spotify writes the Spotify status for Mac
|
||||
Spotify SegmentType = "spotify"
|
||||
//Powerline writes it Powerline style
|
||||
Powerline SegmentStyle = "powerline"
|
||||
//Plain writes it without ornaments
|
||||
Plain SegmentStyle = "plain"
|
||||
//Diamond writes the prompt shaped with a leading and trailing symbol
|
||||
Diamond SegmentStyle = "diamond"
|
||||
)
|
||||
|
||||
func (segment *Segment) string() string {
|
||||
return segment.writer.string()
|
||||
}
|
||||
|
||||
func (segment *Segment) enabled() bool {
|
||||
return segment.writer.enabled()
|
||||
}
|
||||
|
||||
func (segment *Segment) mapSegmentWithWriter(env environmentInfo) *properties {
|
||||
functions := map[SegmentType]SegmentWriter{
|
||||
Session: &session{},
|
||||
Path: &path{},
|
||||
Git: &git{},
|
||||
Exit: &exit{},
|
||||
Venv: &venv{},
|
||||
Root: &root{},
|
||||
Text: &text{},
|
||||
Time: &tempus{},
|
||||
Cmd: &command{},
|
||||
Battery: &batt{},
|
||||
Spotify: &spotify{},
|
||||
}
|
||||
if writer, ok := functions[segment.Type]; ok {
|
||||
props := &properties{
|
||||
values: segment.Properties,
|
||||
foreground: segment.Foreground,
|
||||
background: segment.Background,
|
||||
}
|
||||
writer.init(props, env)
|
||||
segment.writer = writer
|
||||
return props
|
||||
}
|
||||
return nil
|
||||
}
|
70
segment_battery.go
Normal file
70
segment_battery.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/distatus/battery"
|
||||
)
|
||||
|
||||
type batt struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
}
|
||||
|
||||
const (
|
||||
//BatteryIcon to display in front of the battery
|
||||
BatteryIcon Property = "battery_icon"
|
||||
//ChargingIcon to display when charging
|
||||
ChargingIcon Property = "charging_icon"
|
||||
//DischargingIcon o display when discharging
|
||||
DischargingIcon Property = "discharging_icon"
|
||||
//ChargedIcon to display when fully charged
|
||||
ChargedIcon Property = "charged_icon"
|
||||
//ChargedColor to display when fully charged
|
||||
ChargedColor Property = "charged_color"
|
||||
//ChargingColor to display when charging
|
||||
ChargingColor Property = "charging_color"
|
||||
//DischargingColor to display when discharging
|
||||
DischargingColor Property = "discharging_color"
|
||||
)
|
||||
|
||||
func (b *batt) enabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (b *batt) string() string {
|
||||
bt, err := b.env.getBatteryInfo()
|
||||
if err != nil {
|
||||
return "BATT ERR"
|
||||
}
|
||||
batteryPercentage := bt.Current / bt.Full * 100
|
||||
percentageText := fmt.Sprintf("%.0f%%", batteryPercentage)
|
||||
var icon string
|
||||
var colorPorperty Property
|
||||
switch bt.State {
|
||||
case battery.Discharging:
|
||||
colorPorperty = DischargingColor
|
||||
icon = b.props.getString(DischargingIcon, "")
|
||||
case battery.Charging:
|
||||
colorPorperty = ChargingColor
|
||||
icon = b.props.getString(ChargingIcon, "")
|
||||
case battery.Full:
|
||||
colorPorperty = ChargedColor
|
||||
icon = b.props.getString(ChargedIcon, "")
|
||||
default:
|
||||
return percentageText
|
||||
}
|
||||
colorBackground := b.props.getBool(ColorBackground, false)
|
||||
if colorBackground {
|
||||
b.props.background = b.props.getColor(colorPorperty, b.props.background)
|
||||
} else {
|
||||
b.props.foreground = b.props.getColor(colorPorperty, b.props.foreground)
|
||||
}
|
||||
batteryIcon := b.props.getString(BatteryIcon, "")
|
||||
return fmt.Sprintf("%s%s%s", icon, batteryIcon, percentageText)
|
||||
}
|
||||
|
||||
func (b *batt) init(props *properties, env environmentInfo) {
|
||||
b.props = props
|
||||
b.env = env
|
||||
}
|
134
segment_battery_test.go
Normal file
134
segment_battery_test.go
Normal file
|
@ -0,0 +1,134 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/distatus/battery"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestBattery(t *testing.T) {
|
||||
env := &environment{}
|
||||
b := &batt{
|
||||
env: env,
|
||||
props: &properties{},
|
||||
}
|
||||
val := b.string()
|
||||
assert.NotEmpty(t, val)
|
||||
}
|
||||
|
||||
func setupBatteryTests(state battery.State, batteryLevel float64, props *properties) *batt {
|
||||
env := &MockedEnvironment{}
|
||||
bt := &battery.Battery{
|
||||
State: state,
|
||||
Full: 100,
|
||||
Current: batteryLevel,
|
||||
}
|
||||
env.On("getBatteryInfo", nil).Return(bt, nil)
|
||||
return &batt{
|
||||
props: props,
|
||||
env: env,
|
||||
}
|
||||
}
|
||||
|
||||
func TestBatteryCharging(t *testing.T) {
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
ChargingIcon: "charging ",
|
||||
},
|
||||
}
|
||||
b := setupBatteryTests(battery.Charging, 80, props)
|
||||
assert.Equal(t, "charging 80%", b.string())
|
||||
}
|
||||
|
||||
func TestBatteryCharged(t *testing.T) {
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
ChargedIcon: "charged ",
|
||||
},
|
||||
}
|
||||
b := setupBatteryTests(battery.Full, 100, props)
|
||||
assert.Equal(t, "charged 100%", b.string())
|
||||
}
|
||||
|
||||
func TestBatteryDischarging(t *testing.T) {
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
DischargingIcon: "going down ",
|
||||
},
|
||||
}
|
||||
b := setupBatteryTests(battery.Discharging, 70, props)
|
||||
assert.Equal(t, "going down 70%", b.string())
|
||||
}
|
||||
|
||||
func TestBatteryBackgroundColor(t *testing.T) {
|
||||
expected := "#768954"
|
||||
props := &properties{
|
||||
background: "#111111",
|
||||
values: map[Property]interface{}{
|
||||
DischargingIcon: "going down ",
|
||||
ColorBackground: true,
|
||||
DischargingColor: expected,
|
||||
},
|
||||
}
|
||||
b := setupBatteryTests(battery.Discharging, 70, props)
|
||||
b.string()
|
||||
assert.Equal(t, expected, props.background)
|
||||
}
|
||||
|
||||
func TestBatteryBackgroundColorInvalid(t *testing.T) {
|
||||
expected := "#768954"
|
||||
props := &properties{
|
||||
background: expected,
|
||||
values: map[Property]interface{}{
|
||||
DischargingIcon: "going down ",
|
||||
ColorBackground: true,
|
||||
DischargingColor: "derp",
|
||||
},
|
||||
}
|
||||
b := setupBatteryTests(battery.Discharging, 70, props)
|
||||
b.string()
|
||||
assert.Equal(t, expected, props.background)
|
||||
}
|
||||
|
||||
func TestBatteryForegroundColor(t *testing.T) {
|
||||
expected := "#768954"
|
||||
props := &properties{
|
||||
foreground: "#111111",
|
||||
values: map[Property]interface{}{
|
||||
DischargingIcon: "going down ",
|
||||
ColorBackground: false,
|
||||
DischargingColor: expected,
|
||||
},
|
||||
}
|
||||
b := setupBatteryTests(battery.Discharging, 70, props)
|
||||
b.string()
|
||||
assert.Equal(t, expected, props.foreground)
|
||||
}
|
||||
|
||||
func TestBatteryForegroundColorInvalid(t *testing.T) {
|
||||
expected := "#768954"
|
||||
props := &properties{
|
||||
foreground: expected,
|
||||
values: map[Property]interface{}{
|
||||
DischargingIcon: "going down ",
|
||||
ColorBackground: false,
|
||||
DischargingColor: "derp",
|
||||
},
|
||||
}
|
||||
b := setupBatteryTests(battery.Discharging, 70, props)
|
||||
b.string()
|
||||
assert.Equal(t, expected, props.foreground)
|
||||
}
|
||||
|
||||
func TestBatteryError(t *testing.T) {
|
||||
env := &MockedEnvironment{}
|
||||
err := errors.New("oh snap")
|
||||
env.On("getBatteryInfo", nil).Return(&battery.Battery{}, err)
|
||||
b := &batt{
|
||||
props: nil,
|
||||
env: env,
|
||||
}
|
||||
assert.Equal(t, "BATT ERR", b.string())
|
||||
}
|
56
segment_command.go
Normal file
56
segment_command.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package main
|
||||
|
||||
import "strings"
|
||||
|
||||
type command struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
value string
|
||||
}
|
||||
|
||||
const (
|
||||
//Shell to execute command in
|
||||
Shell Property = "shell"
|
||||
//Command to execute
|
||||
Command Property = "command"
|
||||
)
|
||||
|
||||
func (c *command) enabled() bool {
|
||||
shell := c.props.getString(Shell, "bash")
|
||||
command := c.props.getString(Command, "echo no command specified")
|
||||
if strings.Contains(command, "||") {
|
||||
commands := strings.Split(command, "||")
|
||||
for _, cmd := range commands {
|
||||
output := c.env.runShellCommand(shell, cmd)
|
||||
if output != "" {
|
||||
c.value = output
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.Contains(command, "&&") {
|
||||
var output string
|
||||
commands := strings.Split(command, "&&")
|
||||
for _, cmd := range commands {
|
||||
output += c.env.runShellCommand(shell, cmd)
|
||||
}
|
||||
c.value = output
|
||||
return c.value != ""
|
||||
}
|
||||
c.value = c.env.runShellCommand(shell, command)
|
||||
return c.value != ""
|
||||
}
|
||||
|
||||
func (c *command) string() string {
|
||||
return c.value
|
||||
}
|
||||
|
||||
// func (c *command) runCommand(command string) string {
|
||||
// args := strings.Fields(command)
|
||||
// return c.env.runCommand(args[0], args[1:]...)
|
||||
// }
|
||||
|
||||
func (c *command) init(props *properties, env environmentInfo) {
|
||||
c.props = props
|
||||
c.env = env
|
||||
}
|
128
segment_command_test.go
Normal file
128
segment_command_test.go
Normal file
|
@ -0,0 +1,128 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestExecuteCommand(t *testing.T) {
|
||||
env := &environment{}
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
Command: "echo hello",
|
||||
},
|
||||
}
|
||||
c := &command{
|
||||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
assert.True(t, enabled)
|
||||
assert.Equal(t, c.string(), "hello")
|
||||
}
|
||||
|
||||
func TestExecuteMultipleCommandsOrFirst(t *testing.T) {
|
||||
env := &environment{}
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
Command: "exit 1 || echo hello",
|
||||
},
|
||||
}
|
||||
c := &command{
|
||||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
assert.True(t, enabled)
|
||||
assert.Equal(t, c.string(), "hello")
|
||||
}
|
||||
|
||||
func TestExecuteMultipleCommandsOrSecond(t *testing.T) {
|
||||
env := &environment{}
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
Command: "echo hello || echo world",
|
||||
},
|
||||
}
|
||||
c := &command{
|
||||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
assert.True(t, enabled)
|
||||
assert.Equal(t, c.string(), "hello")
|
||||
}
|
||||
|
||||
func TestExecuteMultipleCommandsAnd(t *testing.T) {
|
||||
env := &environment{}
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
Command: "echo hello && echo world",
|
||||
},
|
||||
}
|
||||
c := &command{
|
||||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
assert.True(t, enabled)
|
||||
assert.Equal(t, c.string(), "helloworld")
|
||||
}
|
||||
|
||||
func TestExecuteSingleCommandEmpty(t *testing.T) {
|
||||
env := &environment{}
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
Command: "",
|
||||
},
|
||||
}
|
||||
c := &command{
|
||||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
assert.False(t, enabled)
|
||||
}
|
||||
|
||||
func TestExecuteSingleCommandNoCommandProperty(t *testing.T) {
|
||||
env := &environment{}
|
||||
props := &properties{}
|
||||
c := &command{
|
||||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
assert.True(t, enabled)
|
||||
assert.Equal(t, "no command specified", c.value)
|
||||
}
|
||||
|
||||
func TestExecuteMultipleCommandsAndDisabled(t *testing.T) {
|
||||
env := &environment{}
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
Command: "echo && echo",
|
||||
},
|
||||
}
|
||||
c := &command{
|
||||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
assert.False(t, enabled)
|
||||
}
|
||||
|
||||
func TestExecuteMultipleCommandsOrDisabled(t *testing.T) {
|
||||
env := &environment{}
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
Command: "echo|| echo",
|
||||
},
|
||||
}
|
||||
c := &command{
|
||||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
assert.False(t, enabled)
|
||||
}
|
110
segment_exit.go
Normal file
110
segment_exit.go
Normal file
|
@ -0,0 +1,110 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type exit struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
}
|
||||
|
||||
const (
|
||||
//ErrorIcon represents icon to display in case of error
|
||||
ErrorIcon Property = "error_icon"
|
||||
//DisplayErrorCode shows or hides the error code
|
||||
DisplayErrorCode Property = "display_error_code"
|
||||
//AlwaysEnabled decides whether or not to always display the exitcode info
|
||||
AlwaysEnabled Property = "always_enabled"
|
||||
//ErrorColor specify a different foreground color for the error text when using always_show = true
|
||||
ErrorColor Property = "error_color"
|
||||
)
|
||||
|
||||
func (e *exit) enabled() bool {
|
||||
if e.props.getBool(AlwaysEnabled, false) {
|
||||
return true
|
||||
}
|
||||
return e.env.lastErrorCode() != 0
|
||||
}
|
||||
|
||||
func (e *exit) string() string {
|
||||
return e.getFormattedText()
|
||||
}
|
||||
|
||||
func (e *exit) init(props *properties, env environmentInfo) {
|
||||
e.props = props
|
||||
e.env = env
|
||||
}
|
||||
|
||||
func (e *exit) getFormattedText() string {
|
||||
errorIcon := e.props.getString(ErrorIcon, "X")
|
||||
exitCode := e.getMeaningFromExitCode()
|
||||
colorBackground := e.props.getBool(ColorBackground, false)
|
||||
if e.env.lastErrorCode() != 0 && !colorBackground {
|
||||
e.props.foreground = e.props.getColor(ErrorColor, e.props.foreground)
|
||||
}
|
||||
if e.env.lastErrorCode() != 0 && colorBackground {
|
||||
e.props.background = e.props.getColor(ErrorColor, e.props.background)
|
||||
}
|
||||
return fmt.Sprintf("%s%s", errorIcon, exitCode)
|
||||
}
|
||||
|
||||
func (e *exit) getMeaningFromExitCode() string {
|
||||
if !e.props.getBool(DisplayErrorCode, true) {
|
||||
return ""
|
||||
}
|
||||
switch e.env.lastErrorCode() {
|
||||
case 1:
|
||||
return "ERROR"
|
||||
case 2:
|
||||
return "USAGE"
|
||||
case 126:
|
||||
return "NOPERM"
|
||||
case 127:
|
||||
return "NOTFOUND"
|
||||
case 128 + 1:
|
||||
return "SIGHUP"
|
||||
case 128 + 2:
|
||||
return "SIGINT"
|
||||
case 128 + 3:
|
||||
return "SIGQUIT"
|
||||
case 128 + 4:
|
||||
return "SIGILL"
|
||||
case 128 + 5:
|
||||
return "SIGTRAP"
|
||||
case 128 + 6:
|
||||
return "SIGIOT"
|
||||
case 128 + 7:
|
||||
return "SIGBUS"
|
||||
case 128 + 8:
|
||||
return "SIGFPE"
|
||||
case 128 + 9:
|
||||
return "SIGKILL"
|
||||
case 128 + 10:
|
||||
return "SIGUSR1"
|
||||
case 128 + 11:
|
||||
return "SIGSEGV"
|
||||
case 128 + 12:
|
||||
return "SIGUSR2"
|
||||
case 128 + 13:
|
||||
return "SIGPIPE"
|
||||
case 128 + 14:
|
||||
return "SIGALRM"
|
||||
case 128 + 15:
|
||||
return "SIGTERM"
|
||||
case 128 + 16:
|
||||
return "SIGSTKFLT"
|
||||
case 128 + 17:
|
||||
return "SIGCHLD"
|
||||
case 128 + 18:
|
||||
return "SIGCONT"
|
||||
case 128 + 19:
|
||||
return "SIGSTOP"
|
||||
case 128 + 20:
|
||||
return "SIGTSTP"
|
||||
case 128 + 21:
|
||||
return "SIGTTIN"
|
||||
case 128 + 22:
|
||||
return "SIGTTOU"
|
||||
default:
|
||||
return fmt.Sprintf("%d", e.env.lastErrorCode())
|
||||
}
|
||||
}
|
93
segment_exit_test.go
Normal file
93
segment_exit_test.go
Normal file
|
@ -0,0 +1,93 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestExitWriterEnabled(t *testing.T) {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("lastErrorCode", nil).Return(102)
|
||||
e := &exit{
|
||||
env: env,
|
||||
}
|
||||
assert.True(t, e.enabled())
|
||||
}
|
||||
|
||||
func TestExitWriterDisabled(t *testing.T) {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("lastErrorCode", nil).Return(0)
|
||||
e := &exit{
|
||||
env: env,
|
||||
}
|
||||
assert.False(t, e.enabled())
|
||||
}
|
||||
|
||||
func TestExitWriterStandardCode(t *testing.T) {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("lastErrorCode", nil).Return(129)
|
||||
props := &properties{
|
||||
foreground: "#111111",
|
||||
background: "#ffffff",
|
||||
}
|
||||
e := &exit{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
assert.Equal(t, "XSIGHUP", e.getFormattedText())
|
||||
}
|
||||
|
||||
func TestExitWriterNonStandardCode(t *testing.T) {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("lastErrorCode", nil).Return(5001)
|
||||
props := &properties{
|
||||
foreground: "#111111",
|
||||
background: "#ffffff",
|
||||
}
|
||||
e := &exit{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
assert.Equal(t, "X5001", e.getFormattedText())
|
||||
}
|
||||
|
||||
func TestGetMeaningFromExitCode(t *testing.T) {
|
||||
errorMap := make(map[int]string)
|
||||
errorMap[1] = "ERROR"
|
||||
errorMap[2] = "USAGE"
|
||||
errorMap[126] = "NOPERM"
|
||||
errorMap[127] = "NOTFOUND"
|
||||
errorMap[129] = "SIGHUP"
|
||||
errorMap[130] = "SIGINT"
|
||||
errorMap[131] = "SIGQUIT"
|
||||
errorMap[132] = "SIGILL"
|
||||
errorMap[133] = "SIGTRAP"
|
||||
errorMap[134] = "SIGIOT"
|
||||
errorMap[135] = "SIGBUS"
|
||||
errorMap[136] = "SIGFPE"
|
||||
errorMap[137] = "SIGKILL"
|
||||
errorMap[138] = "SIGUSR1"
|
||||
errorMap[139] = "SIGSEGV"
|
||||
errorMap[140] = "SIGUSR2"
|
||||
errorMap[141] = "SIGPIPE"
|
||||
errorMap[142] = "SIGALRM"
|
||||
errorMap[143] = "SIGTERM"
|
||||
errorMap[144] = "SIGSTKFLT"
|
||||
errorMap[145] = "SIGCHLD"
|
||||
errorMap[146] = "SIGCONT"
|
||||
errorMap[147] = "SIGSTOP"
|
||||
errorMap[148] = "SIGTSTP"
|
||||
errorMap[149] = "SIGTTIN"
|
||||
errorMap[150] = "SIGTTOU"
|
||||
errorMap[151] = "151"
|
||||
errorMap[7000] = "7000"
|
||||
for exitcode, want := range errorMap {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("lastErrorCode", nil).Return(exitcode)
|
||||
e := &exit{
|
||||
env: env,
|
||||
}
|
||||
assert.Equal(t, want, e.getMeaningFromExitCode())
|
||||
}
|
||||
}
|
202
segment_git.go
Executable file
202
segment_git.go
Executable file
|
@ -0,0 +1,202 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type gitRepo struct {
|
||||
working *gitStatus
|
||||
staging *gitStatus
|
||||
ahead int
|
||||
behind int
|
||||
branch string
|
||||
upstream string
|
||||
stashCount int
|
||||
}
|
||||
|
||||
type gitStatus struct {
|
||||
unmerged int
|
||||
deleted int
|
||||
added int
|
||||
modified int
|
||||
untracked int
|
||||
}
|
||||
|
||||
type git struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
repo *gitRepo
|
||||
}
|
||||
|
||||
const (
|
||||
//BranchIcon the icon to use as branch indicator
|
||||
BranchIcon Property = "branch_icon"
|
||||
//BranchIdenticalIcon the icon to display when the remote and local branch are identical
|
||||
BranchIdenticalIcon Property = "branch_identical_icon"
|
||||
//BranchAheadIcon the icon to display when the local branch is ahead of the remote
|
||||
BranchAheadIcon Property = "branch_ahead_icon"
|
||||
//BranchBehindIcon the icon to display when the local branch is behind the remote
|
||||
BranchBehindIcon Property = "branch_behind_icon"
|
||||
//LocalWorkingIcon the icon to use as the local working area changes indicator
|
||||
LocalWorkingIcon Property = "local_working_icon"
|
||||
//LocalStagingIcon the icon to use as the local staging area changes indicator
|
||||
LocalStagingIcon Property = "local_staged_icon"
|
||||
//DisplayStatus shows the status of the repository
|
||||
DisplayStatus Property = "display_status"
|
||||
)
|
||||
|
||||
func (g *git) enabled() bool {
|
||||
if !g.env.hasCommand("git") {
|
||||
return false
|
||||
}
|
||||
output := g.env.runCommand("git", "rev-parse", "--is-inside-work-tree")
|
||||
return output == "true"
|
||||
}
|
||||
|
||||
func (g *git) string() string {
|
||||
g.getGitStatus()
|
||||
buffer := new(bytes.Buffer)
|
||||
// branchsymbol
|
||||
buffer.WriteString(g.props.getString(BranchIcon, "Branch: "))
|
||||
// branchName
|
||||
fmt.Fprintf(buffer, "%s", g.repo.branch)
|
||||
displayStatus := g.props.getBool(DisplayStatus, true)
|
||||
if !displayStatus {
|
||||
return buffer.String()
|
||||
}
|
||||
// TODO: Add upstream gone icon
|
||||
// if ahead, print with symbol
|
||||
if g.repo.ahead > 0 {
|
||||
fmt.Fprintf(buffer, " %s%d", g.props.getString(BranchAheadIcon, "+"), g.repo.ahead)
|
||||
}
|
||||
// if behind, print with symbol
|
||||
if g.repo.behind > 0 {
|
||||
fmt.Fprintf(buffer, " %s%d", g.props.getString(BranchBehindIcon, "-"), g.repo.behind)
|
||||
}
|
||||
if g.repo.behind == 0 && g.repo.ahead == 0 {
|
||||
fmt.Fprintf(buffer, " %s", g.props.getString(BranchIdenticalIcon, "="))
|
||||
}
|
||||
// if staging, print that part
|
||||
if g.hasStaging() {
|
||||
fmt.Fprintf(buffer, " %s +%d ~%d -%d", g.props.getString(LocalStagingIcon, "~"), g.repo.staging.added, g.repo.staging.modified, g.repo.staging.deleted)
|
||||
}
|
||||
// if working, print that part
|
||||
if g.hasWorking() {
|
||||
fmt.Fprintf(buffer, " %s +%d ~%d -%d", g.props.getString(LocalWorkingIcon, "#"), g.repo.working.added+g.repo.working.untracked, g.repo.working.modified, g.repo.working.deleted)
|
||||
}
|
||||
// TODO: Add stash entries
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
func (g *git) init(props *properties, env environmentInfo) {
|
||||
g.props = props
|
||||
g.env = env
|
||||
}
|
||||
|
||||
func (g *git) getGitStatus() {
|
||||
g.repo = &gitRepo{}
|
||||
output := g.getGitOutputForCommand("status", "--porcelain", "-b", "--ignore-submodules")
|
||||
splittedOutput := strings.Split(output, "\n")
|
||||
g.repo.working = g.parseGitStats(splittedOutput, true)
|
||||
g.repo.staging = g.parseGitStats(splittedOutput, false)
|
||||
branchInfo := g.parseGitBranchInfo(splittedOutput[0])
|
||||
if branchInfo["local"] != "" {
|
||||
g.repo.ahead, _ = strconv.Atoi(branchInfo["ahead"])
|
||||
g.repo.behind, _ = strconv.Atoi(branchInfo["behind"])
|
||||
g.repo.branch = branchInfo["local"]
|
||||
g.repo.upstream = branchInfo["upstream"]
|
||||
} else {
|
||||
g.repo.branch = g.getGitDetachedBranch()
|
||||
}
|
||||
g.repo.stashCount = g.getStashContext()
|
||||
}
|
||||
|
||||
func (g *git) getGitOutputForCommand(args ...string) string {
|
||||
args = append([]string{"-c", "core.quotepath=false", "-c", "color.status=false"}, args...)
|
||||
return g.env.runCommand("git", args...)
|
||||
}
|
||||
|
||||
func (g *git) getGitDetachedBranch() string {
|
||||
ref := g.getGitOutputForCommand("symbolic-ref", "--short", "HEAD")
|
||||
if ref == "" {
|
||||
return "unknown"
|
||||
}
|
||||
return ref
|
||||
}
|
||||
|
||||
func (g *git) parseGitStats(output []string, working bool) *gitStatus {
|
||||
status := gitStatus{}
|
||||
if len(output) <= 1 {
|
||||
return &status
|
||||
}
|
||||
for _, line := range output[1:] {
|
||||
if len(line) < 2 {
|
||||
continue
|
||||
}
|
||||
code := line[0:1]
|
||||
if working {
|
||||
code = line[1:2]
|
||||
}
|
||||
switch code {
|
||||
case "?":
|
||||
status.untracked++
|
||||
case "D":
|
||||
status.deleted++
|
||||
case "A":
|
||||
status.added++
|
||||
case "U":
|
||||
status.unmerged++
|
||||
case "M", "R", "C":
|
||||
status.modified++
|
||||
}
|
||||
}
|
||||
return &status
|
||||
}
|
||||
|
||||
func (g *git) getStashContext() int {
|
||||
stash := g.getGitOutputForCommand("stash", "list")
|
||||
return numberOfLinesInString(stash)
|
||||
}
|
||||
|
||||
func (g *git) hasStaging() bool {
|
||||
return g.repo.staging.deleted > 0 || g.repo.staging.added > 0 || g.repo.staging.unmerged > 0 || g.repo.staging.modified > 0
|
||||
}
|
||||
|
||||
func (g *git) hasWorking() bool {
|
||||
return g.repo.working.deleted > 0 || g.repo.working.added > 0 || g.repo.working.unmerged > 0 || g.repo.working.modified > 0 || g.repo.working.untracked > 0
|
||||
}
|
||||
|
||||
func (g *git) parseGitBranchInfo(branchInfo string) map[string]string {
|
||||
var branchRegex = regexp.MustCompile(`^## (?P<local>\S+?)(\.{3}(?P<upstream>\S+?)( \[(ahead (?P<ahead>\d+)(, )?)?(behind (?P<behind>\d+))?])?)?$`)
|
||||
return groupDict(branchRegex, branchInfo)
|
||||
}
|
||||
|
||||
func groupDict(pattern *regexp.Regexp, haystack string) map[string]string {
|
||||
match := pattern.FindStringSubmatch(haystack)
|
||||
result := make(map[string]string)
|
||||
if len(match) > 0 {
|
||||
for i, name := range pattern.SubexpNames() {
|
||||
if i != 0 {
|
||||
result[name] = match[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func numberOfLinesInString(s string) int {
|
||||
n := 0
|
||||
for _, r := range s {
|
||||
if r == '\n' {
|
||||
n++
|
||||
}
|
||||
}
|
||||
if len(s) > 0 && !strings.HasSuffix(s, "\n") {
|
||||
n++
|
||||
}
|
||||
return n
|
||||
}
|
148
segment_git_test.go
Executable file
148
segment_git_test.go
Executable file
|
@ -0,0 +1,148 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEnabledGitNotFound(t *testing.T) {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("hasCommand", "git").Return(false)
|
||||
g := &git{
|
||||
env: env,
|
||||
}
|
||||
assert.False(t, g.enabled())
|
||||
}
|
||||
|
||||
func TestEnabledInWorkingDirectory(t *testing.T) {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("hasCommand", "git").Return(true)
|
||||
env.On("runCommand", "git", []string{"rev-parse", "--is-inside-work-tree"}).Return("true")
|
||||
g := &git{
|
||||
env: env,
|
||||
}
|
||||
assert.True(t, g.enabled())
|
||||
}
|
||||
|
||||
func TestGetGitOutputForCommand(t *testing.T) {
|
||||
args := []string{"-c", "core.quotepath=false", "-c", "color.status=false"}
|
||||
commandArgs := []string{"symbolic-ref", "--short", "HEAD"}
|
||||
want := "je suis le output"
|
||||
env := new(MockedEnvironment)
|
||||
env.On("runCommand", "git", append(args, commandArgs...)).Return(want)
|
||||
g := &git{
|
||||
env: env,
|
||||
}
|
||||
got := g.getGitOutputForCommand(commandArgs...)
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestGetGitDetachedBranch(t *testing.T) {
|
||||
want := "master"
|
||||
env := new(MockedEnvironment)
|
||||
env.On("runCommand", "git", []string{"-c", "core.quotepath=false", "-c", "color.status=false", "symbolic-ref", "--short", "HEAD"}).Return(want)
|
||||
g := &git{
|
||||
env: env,
|
||||
}
|
||||
got := g.getGitDetachedBranch()
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestGetGitDetachedBranchEmpty(t *testing.T) {
|
||||
want := "unknown"
|
||||
env := new(MockedEnvironment)
|
||||
env.On("runCommand", "git", []string{"-c", "core.quotepath=false", "-c", "color.status=false", "symbolic-ref", "--short", "HEAD"}).Return("")
|
||||
g := &git{
|
||||
env: env,
|
||||
}
|
||||
got := g.getGitDetachedBranch()
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestGetStashContextZeroEntries(t *testing.T) {
|
||||
want := 0
|
||||
env := new(MockedEnvironment)
|
||||
env.On("runCommand", "git", []string{"-c", "core.quotepath=false", "-c", "color.status=false", "stash", "list"}).Return("")
|
||||
g := &git{
|
||||
env: env,
|
||||
}
|
||||
got := g.getStashContext()
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestGetStashContextMultipleEntries(t *testing.T) {
|
||||
want := rand.Intn(100)
|
||||
var response string
|
||||
for i := 0; i < want; i++ {
|
||||
response += "I'm a stash entry\n"
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
env.On("runCommand", "git", []string{"-c", "core.quotepath=false", "-c", "color.status=false", "stash", "list"}).Return(response)
|
||||
g := &git{
|
||||
env: env,
|
||||
}
|
||||
got := g.getStashContext()
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestGetStashContextOneEntry(t *testing.T) {
|
||||
want := 1
|
||||
env := new(MockedEnvironment)
|
||||
env.On("runCommand", "git", []string{"-c", "core.quotepath=false", "-c", "color.status=false", "stash", "list"}).Return("stash entry")
|
||||
g := &git{
|
||||
env: env,
|
||||
}
|
||||
got := g.getStashContext()
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestParseGitBranchInfoEqual(t *testing.T) {
|
||||
g := git{}
|
||||
branchInfo := "## master...origin/master"
|
||||
got := g.parseGitBranchInfo(branchInfo)
|
||||
assert.Equal(t, "master", got["local"])
|
||||
assert.Equal(t, "origin/master", got["upstream"])
|
||||
assert.Empty(t, got["ahead"])
|
||||
assert.Empty(t, got["behind"])
|
||||
}
|
||||
|
||||
func TestParseGitBranchInfoAhead(t *testing.T) {
|
||||
g := git{}
|
||||
branchInfo := "## master...origin/master [ahead 1]"
|
||||
got := g.parseGitBranchInfo(branchInfo)
|
||||
assert.Equal(t, "master", got["local"])
|
||||
assert.Equal(t, "origin/master", got["upstream"])
|
||||
assert.Equal(t, "1", got["ahead"])
|
||||
assert.Empty(t, got["behind"])
|
||||
}
|
||||
|
||||
func TestParseGitBranchInfoBehind(t *testing.T) {
|
||||
g := git{}
|
||||
branchInfo := "## master...origin/master [behind 1]"
|
||||
got := g.parseGitBranchInfo(branchInfo)
|
||||
assert.Equal(t, "master", got["local"])
|
||||
assert.Equal(t, "origin/master", got["upstream"])
|
||||
assert.Equal(t, "1", got["behind"])
|
||||
assert.Empty(t, got["ahead"])
|
||||
}
|
||||
|
||||
func TestParseGitBranchInfoBehindandAhead(t *testing.T) {
|
||||
g := git{}
|
||||
branchInfo := "## master...origin/master [ahead 1, behind 2]"
|
||||
got := g.parseGitBranchInfo(branchInfo)
|
||||
assert.Equal(t, "master", got["local"])
|
||||
assert.Equal(t, "origin/master", got["upstream"])
|
||||
assert.Equal(t, "2", got["behind"])
|
||||
assert.Equal(t, "1", got["ahead"])
|
||||
}
|
||||
|
||||
// func TestGetGitStatus(t *testing.T) {
|
||||
// env := new(environment)
|
||||
// writer := gitWriter{
|
||||
// env: env,
|
||||
// }
|
||||
// writer.getGitStatus()
|
||||
// assert.NotEmpty(t, writer.repo)
|
||||
// }
|
167
segment_path.go
Executable file
167
segment_path.go
Executable file
|
@ -0,0 +1,167 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type path struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
}
|
||||
|
||||
const (
|
||||
//FolderSeparatorIcon the path which is split will be separated by this icon
|
||||
FolderSeparatorIcon Property = "folder_separator_icon"
|
||||
//HomeIcon indicates the $HOME location
|
||||
HomeIcon Property = "home_icon"
|
||||
//FolderIcon identifies one folder
|
||||
FolderIcon Property = "folder_icon"
|
||||
//WindowsRegistryIcon indicates the registry location on Windows
|
||||
WindowsRegistryIcon Property = "windows_registry_icon"
|
||||
//Agnoster displays a short path with separator icon, this the default style
|
||||
Agnoster string = "agnoster"
|
||||
//Short displays a shorter path
|
||||
Short string = "short"
|
||||
//Full displays the full path
|
||||
Full string = "full"
|
||||
//Folder displays the current folder
|
||||
Folder string = "folder"
|
||||
)
|
||||
|
||||
func (pt *path) enabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (pt *path) string() string {
|
||||
switch style := pt.props.getString(Style, Agnoster); style {
|
||||
case Agnoster:
|
||||
return pt.getAgnosterPath()
|
||||
case Short:
|
||||
return pt.getShortPath()
|
||||
case Full:
|
||||
return pt.workingDir()
|
||||
case Folder:
|
||||
return base(pt.workingDir(), pt.env)
|
||||
default:
|
||||
return fmt.Sprintf("Path style: %s is not available", style)
|
||||
}
|
||||
}
|
||||
|
||||
func (pt *path) init(props *properties, env environmentInfo) {
|
||||
pt.props = props
|
||||
pt.env = env
|
||||
}
|
||||
|
||||
func (pt *path) getShortPath() string {
|
||||
pwd := pt.workingDir()
|
||||
mappedLocations := map[string]string{
|
||||
"HKCU:": pt.props.getString(WindowsRegistryIcon, "HK:"),
|
||||
"Microsoft.PowerShell.Core\\FileSystem::": "",
|
||||
pt.homeDir(): pt.props.getString(HomeIcon, "~"),
|
||||
}
|
||||
for location, value := range mappedLocations {
|
||||
if strings.HasPrefix(pwd, location) {
|
||||
return strings.Replace(pwd, location, value, 1)
|
||||
}
|
||||
}
|
||||
return pwd
|
||||
}
|
||||
|
||||
func (pt *path) getAgnosterPath() string {
|
||||
pwd := pt.workingDir()
|
||||
buffer := new(bytes.Buffer)
|
||||
buffer.WriteString(pt.rootLocation(pwd))
|
||||
pathDepth := pt.pathDepth(pwd)
|
||||
for i := 1; i < pathDepth; i++ {
|
||||
buffer.WriteString(fmt.Sprintf("%s%s", pt.props.getString(FolderSeparatorIcon, pt.env.getPathSeperator()), pt.props.getString(FolderIcon, "..")))
|
||||
}
|
||||
if pathDepth > 0 {
|
||||
buffer.WriteString(fmt.Sprintf("%s%s", pt.props.getString(FolderSeparatorIcon, pt.env.getPathSeperator()), base(pwd, pt.env)))
|
||||
}
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
func (pt *path) workingDir() string {
|
||||
dir, err := pt.env.getwd()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
func (pt *path) homeDir() string {
|
||||
// On Unix systems, $HOME comes with a trailing slash, unlike the Windows variant
|
||||
home := pt.env.getenv("HOME")
|
||||
return home
|
||||
}
|
||||
|
||||
func (pt *path) inHomeDir(pwd string) bool {
|
||||
return strings.HasPrefix(pwd, pt.homeDir())
|
||||
}
|
||||
|
||||
func (pt *path) rootLocation(pwd string) string {
|
||||
//See https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/correcting-powershell-paths
|
||||
if strings.HasPrefix(pwd, "Microsoft.PowerShell.Core\\FileSystem::") {
|
||||
pwd = strings.Replace(pwd, "Microsoft.PowerShell.Core\\FileSystem::", "", 1)
|
||||
}
|
||||
if pt.inHomeDir(pwd) {
|
||||
return pt.props.getString(HomeIcon, "~")
|
||||
}
|
||||
pwd = strings.TrimPrefix(pwd, pt.env.getPathSeperator())
|
||||
splitted := strings.Split(pwd, pt.env.getPathSeperator())
|
||||
rootLocation := splitted[0]
|
||||
mappedLocations := map[string]string{
|
||||
"HKCU:": pt.props.getString(WindowsRegistryIcon, "HK:"),
|
||||
}
|
||||
if val, ok := mappedLocations[rootLocation]; ok {
|
||||
return val
|
||||
}
|
||||
return rootLocation
|
||||
}
|
||||
|
||||
func (pt *path) pathDepth(pwd string) int {
|
||||
if pt.inHomeDir(pwd) {
|
||||
pwd = strings.Replace(pwd, pt.homeDir(), "root", 1)
|
||||
}
|
||||
splitted := strings.Split(pwd, pt.env.getPathSeperator())
|
||||
var validParts []string
|
||||
for _, part := range splitted {
|
||||
if part != "" {
|
||||
validParts = append(validParts, part)
|
||||
}
|
||||
}
|
||||
depth := len(validParts)
|
||||
return depth - 1
|
||||
}
|
||||
|
||||
// Base returns the last element of path.
|
||||
// Trailing path separators are removed before extracting the last element.
|
||||
// If the path is empty, Base returns ".".
|
||||
// If the path consists entirely of separators, Base returns a single separator.
|
||||
func base(path string, env environmentInfo) string {
|
||||
if path == "" {
|
||||
return "."
|
||||
}
|
||||
// Strip trailing slashes.
|
||||
for len(path) > 0 && string(path[len(path)-1]) == env.getPathSeperator() {
|
||||
path = path[0 : len(path)-1]
|
||||
}
|
||||
// Throw away volume name
|
||||
path = path[len(filepath.VolumeName(path)):]
|
||||
// Find the last element
|
||||
i := len(path) - 1
|
||||
for i >= 0 && string(path[i]) != env.getPathSeperator() {
|
||||
i--
|
||||
}
|
||||
if i >= 0 {
|
||||
path = path[i+1:]
|
||||
}
|
||||
// If empty now, it had only slashes.
|
||||
if path == "" {
|
||||
return string(env.getPathSeperator())
|
||||
}
|
||||
return path
|
||||
}
|
424
segment_path_test.go
Executable file
424
segment_path_test.go
Executable file
|
@ -0,0 +1,424 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"os/user"
|
||||
"testing"
|
||||
|
||||
"github.com/distatus/battery"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
type MockedEnvironment struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) getenv(key string) string {
|
||||
args := env.Called(key)
|
||||
return args.String(0)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) getwd() (string, error) {
|
||||
args := env.Called(nil)
|
||||
return args.String(0), args.Error(1)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) getPathSeperator() string {
|
||||
args := env.Called(nil)
|
||||
return args.String(0)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) getCurrentUser() (*user.User, error) {
|
||||
args := env.Called(nil)
|
||||
return args.Get(0).(*user.User), args.Error(1)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) getHostName() (string, error) {
|
||||
args := env.Called(nil)
|
||||
return args.String(0), args.Error(1)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) getRuntimeGOOS() string {
|
||||
args := env.Called(nil)
|
||||
return args.String(0)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) hasCommand(command string) bool {
|
||||
args := env.Called(command)
|
||||
return args.Bool(0)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) runCommand(command string, args ...string) string {
|
||||
arguments := env.Called(command, args)
|
||||
return arguments.String(0)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) runShellCommand(shell string, command string) string {
|
||||
args := env.Called(shell, command)
|
||||
return args.String(0)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) lastErrorCode() int {
|
||||
args := env.Called(nil)
|
||||
return args.Int(0)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) isRunningAsRoot() bool {
|
||||
args := env.Called(nil)
|
||||
return args.Bool(0)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) getArgs() *args {
|
||||
arguments := env.Called(nil)
|
||||
return arguments.Get(0).(*args)
|
||||
}
|
||||
|
||||
func (env *MockedEnvironment) getBatteryInfo() (*battery.Battery, error) {
|
||||
args := env.Called(nil)
|
||||
return args.Get(0).(*battery.Battery), args.Error(1)
|
||||
}
|
||||
|
||||
func TestWorkingDir(t *testing.T) {
|
||||
want := "/usr/err"
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getwd", nil).Return(want, nil)
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.workingDir()
|
||||
assert.EqualValues(t, want, got)
|
||||
}
|
||||
|
||||
func TestWorkingDirError(t *testing.T) {
|
||||
env := new(MockedEnvironment)
|
||||
expectedError := errors.New("emit macho dwarf: elf header corrupted")
|
||||
env.On("getwd", nil).Return("random", expectedError)
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.workingDir()
|
||||
assert.EqualValues(t, "", got)
|
||||
}
|
||||
|
||||
func TestHomeDir(t *testing.T) {
|
||||
want := "/mnt/Users/Bill"
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return(want)
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.homeDir()
|
||||
assert.EqualValues(t, want, got)
|
||||
}
|
||||
|
||||
func TestIsInHomeDirTrue(t *testing.T) {
|
||||
home := "/home/bill"
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return(home)
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.inHomeDir(home)
|
||||
assert.True(t, got)
|
||||
}
|
||||
|
||||
func TestIsInHomeDirLevelTrue(t *testing.T) {
|
||||
level := rand.Intn(100)
|
||||
home := "/home/bill"
|
||||
pwd := home
|
||||
for i := 0; i < level; i++ {
|
||||
pwd += "/level"
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return(home)
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.inHomeDir(pwd)
|
||||
assert.True(t, got)
|
||||
}
|
||||
|
||||
func TestRootLocationHome(t *testing.T) {
|
||||
expected := "~"
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{HomeIcon: expected},
|
||||
}
|
||||
home := "/home/bill/"
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return("/home/bill")
|
||||
env.On("getPathSeperator", nil).Return("/")
|
||||
path := &path{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
got := path.rootLocation(home)
|
||||
assert.EqualValues(t, expected, got)
|
||||
}
|
||||
|
||||
func TestRootLocationOutsideHome(t *testing.T) {
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{HomeIcon: "~"},
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return("/home/bill")
|
||||
env.On("getPathSeperator", nil).Return("/")
|
||||
path := &path{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
got := path.rootLocation("/usr/error/what")
|
||||
assert.EqualValues(t, "usr", got)
|
||||
}
|
||||
|
||||
func TestRootLocationWindowsDrive(t *testing.T) {
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{HomeIcon: "~"},
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return("C:\\Users\\Bill")
|
||||
env.On("getPathSeperator", nil).Return("\\")
|
||||
path := &path{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
got := path.rootLocation("C:\\Program Files\\Go")
|
||||
assert.EqualValues(t, "C:", got)
|
||||
}
|
||||
|
||||
func TestRootLocationWindowsRegistry(t *testing.T) {
|
||||
expected := "REG"
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{WindowsRegistryIcon: expected},
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return("C:\\Users\\Bill")
|
||||
env.On("getPathSeperator", nil).Return("\\")
|
||||
path := &path{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
got := path.rootLocation("HKCU:\\Program Files\\Go")
|
||||
assert.EqualValues(t, expected, got)
|
||||
}
|
||||
|
||||
func TestRootLocationWindowsPowerShellHome(t *testing.T) {
|
||||
expected := "~"
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{HomeIcon: expected},
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return("C:\\Users\\Bill")
|
||||
env.On("getPathSeperator", nil).Return("\\")
|
||||
path := &path{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
got := path.rootLocation("Microsoft.PowerShell.Core\\FileSystem::C:\\Users\\Bill")
|
||||
assert.EqualValues(t, expected, got)
|
||||
}
|
||||
|
||||
func TestRootLocationWindowsPowerShellOutsideHome(t *testing.T) {
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{WindowsRegistryIcon: "REG"},
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return("C:\\Program Files\\Go")
|
||||
env.On("getPathSeperator", nil).Return("\\")
|
||||
path := &path{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
got := path.rootLocation("Microsoft.PowerShell.Core\\FileSystem::C:\\Users\\Bill")
|
||||
assert.EqualValues(t, "C:", got)
|
||||
}
|
||||
|
||||
func TestRootLocationEmptyDir(t *testing.T) {
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{WindowsRegistryIcon: "REG"},
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return("/home/bill")
|
||||
env.On("getPathSeperator", nil).Return("/")
|
||||
path := &path{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
got := path.rootLocation("")
|
||||
assert.EqualValues(t, "", got)
|
||||
}
|
||||
|
||||
func TestIsInHomeDirFalse(t *testing.T) {
|
||||
home := "/home/bill"
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return(home)
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.inHomeDir("/usr/error")
|
||||
assert.False(t, got)
|
||||
}
|
||||
|
||||
func TestPathDepthInHome(t *testing.T) {
|
||||
home := "/home/bill"
|
||||
pwd := home
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return(home)
|
||||
env.On("getPathSeperator", nil).Return("/")
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.pathDepth(pwd)
|
||||
assert.Equal(t, 0, got)
|
||||
}
|
||||
|
||||
func TestPathDepthInHomeTrailing(t *testing.T) {
|
||||
home := "/home/bill/"
|
||||
pwd := home + "/"
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return(home)
|
||||
env.On("getPathSeperator", nil).Return("/")
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.pathDepth(pwd)
|
||||
assert.Equal(t, 0, got)
|
||||
}
|
||||
|
||||
func TestPathDepthInHomeMultipleLevelsDeep(t *testing.T) {
|
||||
level := rand.Intn(100)
|
||||
home := "/home/bill"
|
||||
pwd := home
|
||||
for i := 0; i < level; i++ {
|
||||
pwd += "/level"
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return(home)
|
||||
env.On("getPathSeperator", nil).Return("/")
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.pathDepth(pwd)
|
||||
assert.Equal(t, level, got)
|
||||
}
|
||||
|
||||
func TestPathDepthOutsideHomeMultipleLevelsDeep(t *testing.T) {
|
||||
level := rand.Intn(100)
|
||||
home := "/home/gates"
|
||||
pwd := "/usr"
|
||||
for i := 0; i < level; i++ {
|
||||
pwd += "/level"
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return(home)
|
||||
env.On("getPathSeperator", nil).Return("/")
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.pathDepth(pwd)
|
||||
assert.Equal(t, level, got)
|
||||
}
|
||||
|
||||
func TestPathDepthOutsideHomeZeroLevelsDeep(t *testing.T) {
|
||||
home := "/home/gates"
|
||||
pwd := "/usr/"
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return(home)
|
||||
env.On("getPathSeperator", nil).Return("/")
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.pathDepth(pwd)
|
||||
assert.Equal(t, 0, got)
|
||||
}
|
||||
|
||||
func TestPathDepthOutsideHomeOneLevelDeep(t *testing.T) {
|
||||
home := "/home/gates"
|
||||
pwd := "/usr/location"
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return(home)
|
||||
env.On("getPathSeperator", nil).Return("/")
|
||||
path := &path{
|
||||
env: env,
|
||||
}
|
||||
got := path.pathDepth(pwd)
|
||||
assert.Equal(t, 1, got)
|
||||
}
|
||||
|
||||
func testWritePathInfo(home string, pwd string, pathSeparator string) string {
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
FolderSeparatorIcon: " > ",
|
||||
FolderIcon: "f",
|
||||
HomeIcon: "~",
|
||||
},
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "HOME").Return(home)
|
||||
env.On("getPathSeperator", nil).Return(pathSeparator)
|
||||
env.On("getwd", nil).Return(pwd, nil)
|
||||
path := &path{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
return path.getAgnosterPath()
|
||||
}
|
||||
|
||||
func TestWritePathInfoWindowsOutsideHome(t *testing.T) {
|
||||
home := "C:\\Users\\Bill"
|
||||
want := "C: > f > f > location"
|
||||
got := testWritePathInfo(home, "C:\\Program Files\\Go\\location", "\\")
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestWritePathInfoWindowsInsideHome(t *testing.T) {
|
||||
home := "C:\\Users\\Bill"
|
||||
location := home + "\\Documents\\Bill\\location"
|
||||
want := "~ > f > f > location"
|
||||
got := testWritePathInfo(home, location, "\\")
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestWritePathInfoWindowsOutsideHomeZeroLevels(t *testing.T) {
|
||||
home := "C:\\Users\\Bill"
|
||||
want := "C: > location"
|
||||
got := testWritePathInfo(home, "C:\\location", "\\")
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestWritePathInfoWindowsOutsideHomeOneLevels(t *testing.T) {
|
||||
home := "C:\\Users\\Bill"
|
||||
want := "C: > f > location"
|
||||
got := testWritePathInfo(home, "C:\\Program Files\\location", "\\")
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestWritePathInfoUnixOutsideHome(t *testing.T) {
|
||||
home := "/usr/home/jan"
|
||||
want := "mnt > f > f > location"
|
||||
got := testWritePathInfo(home, "/mnt/go/test/location", "/")
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestWritePathInfoUnixInsideHome(t *testing.T) {
|
||||
home := "/usr/home/jan"
|
||||
location := home + "/docs/jan/location"
|
||||
want := "~ > f > f > location"
|
||||
got := testWritePathInfo(home, location, "/")
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestWritePathInfoUnixOutsideHomeZeroLevels(t *testing.T) {
|
||||
home := "/usr/home/jan"
|
||||
want := "mnt > location"
|
||||
got := testWritePathInfo(home, "/mnt/location", "/")
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestWritePathInfoUnixOutsideHomeOneLevels(t *testing.T) {
|
||||
home := "/usr/home/jan"
|
||||
want := "mnt > f > location"
|
||||
got := testWritePathInfo(home, "/mnt/folder/location", "/")
|
||||
assert.Equal(t, want, got)
|
||||
}
|
24
segment_root.go
Normal file
24
segment_root.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
type root struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
}
|
||||
|
||||
const (
|
||||
//RootIcon indicates the root user
|
||||
RootIcon Property = "root_icon"
|
||||
)
|
||||
|
||||
func (rt *root) enabled() bool {
|
||||
return rt.env.isRunningAsRoot()
|
||||
}
|
||||
|
||||
func (rt *root) string() string {
|
||||
return rt.props.getString(RootIcon, "#")
|
||||
}
|
||||
|
||||
func (rt *root) init(props *properties, env environmentInfo) {
|
||||
rt.props = props
|
||||
rt.env = env
|
||||
}
|
69
segment_session.go
Executable file
69
segment_session.go
Executable file
|
@ -0,0 +1,69 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type session struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
}
|
||||
|
||||
const (
|
||||
//UserInfoSeparator is put between the user and computer name
|
||||
UserInfoSeparator Property = "user_info_separator"
|
||||
//UserColor if set, is used to color the user name
|
||||
UserColor Property = "user_color"
|
||||
//ComputerColor if set, is used to color the computer name
|
||||
ComputerColor Property = "computer_color"
|
||||
//DisplayComputer hides or show the computer name
|
||||
DisplayComputer Property = "display_computer"
|
||||
//DisplayUser hides or shows the user name
|
||||
DisplayUser Property = "display_user"
|
||||
)
|
||||
|
||||
func (s *session) enabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *session) string() string {
|
||||
return s.getFormattedText()
|
||||
}
|
||||
|
||||
func (s *session) init(props *properties, env environmentInfo) {
|
||||
s.props = props
|
||||
s.env = env
|
||||
}
|
||||
|
||||
func (s *session) getFormattedText() string {
|
||||
username := s.getUserName()
|
||||
computername := s.getComputerName()
|
||||
return fmt.Sprintf("<%s>%s</>%s<%s>%s</>", s.props.getColor(UserColor, s.props.foreground), username, s.props.getString(UserInfoSeparator, "@"), s.props.getColor(ComputerColor, s.props.foreground), computername)
|
||||
}
|
||||
|
||||
func (s *session) getComputerName() string {
|
||||
if !s.props.getBool(DisplayComputer, true) {
|
||||
return ""
|
||||
}
|
||||
computername, err := s.env.getHostName()
|
||||
if err != nil {
|
||||
computername = "unknown"
|
||||
}
|
||||
return strings.TrimSpace(computername)
|
||||
}
|
||||
|
||||
func (s *session) getUserName() string {
|
||||
if !s.props.getBool(DisplayUser, true) {
|
||||
return ""
|
||||
}
|
||||
user, err := s.env.getCurrentUser()
|
||||
if err != nil {
|
||||
return "unknown"
|
||||
}
|
||||
username := strings.TrimSpace(user.Username)
|
||||
if s.env.getRuntimeGOOS() == "windows" && strings.Contains(username, "\\") {
|
||||
username = strings.Split(username, "\\")[1]
|
||||
}
|
||||
return username
|
||||
}
|
40
segment_session_test.go
Executable file
40
segment_session_test.go
Executable file
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os/user"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func testUserInfoWriter(userInfoSeparator string, username string, hostname string, goos string) string {
|
||||
env := new(MockedEnvironment)
|
||||
user := user.User{
|
||||
Username: username,
|
||||
}
|
||||
env.On("getCurrentUser", nil).Return(&user, nil)
|
||||
env.On("getHostName", nil).Return(hostname, nil)
|
||||
env.On("getRuntimeGOOS", nil).Return(goos)
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{UserInfoSeparator: userInfoSeparator},
|
||||
foreground: "#fff",
|
||||
background: "#000",
|
||||
}
|
||||
s := session{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
return s.getFormattedText()
|
||||
}
|
||||
|
||||
func TestWriteUserInfo(t *testing.T) {
|
||||
want := "<#fff>bill</>@<#fff>surface</>"
|
||||
got := testUserInfoWriter("@", "bill", "surface", "windows")
|
||||
assert.EqualValues(t, want, got)
|
||||
}
|
||||
|
||||
func TestWriteUserInfoWindowsIncludingHostname(t *testing.T) {
|
||||
want := "<#fff>bill</>@<#fff>surface</>"
|
||||
got := testUserInfoWriter("@", "surface\\bill", "surface", "windows")
|
||||
assert.EqualValues(t, want, got)
|
||||
}
|
65
segment_spotify.go
Normal file
65
segment_spotify.go
Normal file
|
@ -0,0 +1,65 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type spotify struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
status string
|
||||
artist string
|
||||
track string
|
||||
}
|
||||
|
||||
const (
|
||||
//PlayingIcon indicates a song is playing
|
||||
PlayingIcon Property = "playing_icon"
|
||||
//PausedIcon indicates a song is paused
|
||||
PausedIcon Property = "paused_icon"
|
||||
//TrackSeparator is put between the artist and the track
|
||||
TrackSeparator Property = "track_separator"
|
||||
)
|
||||
|
||||
func (s *spotify) enabled() bool {
|
||||
if s.env.getRuntimeGOOS() != "darwin" {
|
||||
return false
|
||||
}
|
||||
var err error
|
||||
// Check if running
|
||||
running := s.runAppleScriptCommand("application \"Spotify\" is running")
|
||||
if running == "false" || running == "" {
|
||||
return false
|
||||
}
|
||||
s.status = s.runAppleScriptCommand("tell application \"Spotify\" to player state as string")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if s.status == "stopped" {
|
||||
return false
|
||||
}
|
||||
s.artist = s.runAppleScriptCommand("tell application \"Spotify\" to artist of current track as string")
|
||||
s.track = s.runAppleScriptCommand("tell application \"Spotify\" to name of current track as string")
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *spotify) string() string {
|
||||
icon := ""
|
||||
switch s.status {
|
||||
case "paused":
|
||||
icon = s.props.getString(PausedIcon, "")
|
||||
case "playing":
|
||||
icon = s.props.getString(PlayingIcon, "")
|
||||
}
|
||||
separator := s.props.getString(TrackSeparator, " - ")
|
||||
return fmt.Sprintf("%s%s%s%s", icon, s.artist, separator, s.track)
|
||||
}
|
||||
|
||||
func (s *spotify) init(props *properties, env environmentInfo) {
|
||||
s.props = props
|
||||
s.env = env
|
||||
}
|
||||
|
||||
func (s *spotify) runAppleScriptCommand(command string) string {
|
||||
return s.env.runCommand("osascript", "-e", command)
|
||||
}
|
11
segment_spotify_test.go
Executable file
11
segment_spotify_test.go
Executable file
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSpotifyEnabled(t *testing.T) {
|
||||
assert.True(t, true)
|
||||
}
|
25
segment_test.go
Executable file
25
segment_test.go
Executable file
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMapSegmentWriterCanMap(t *testing.T) {
|
||||
sc := &Segment{
|
||||
Type: Session,
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
sc.mapSegmentWithWriter(env)
|
||||
assert.NotNil(t, sc.writer)
|
||||
}
|
||||
|
||||
func TestMapSegmentWriterCannotMap(t *testing.T) {
|
||||
sc := &Segment{
|
||||
Type: "nilwriter",
|
||||
}
|
||||
env := new(MockedEnvironment)
|
||||
sc.mapSegmentWithWriter(env)
|
||||
assert.Nil(t, sc.writer)
|
||||
}
|
25
segment_text.go
Normal file
25
segment_text.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
type text struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
}
|
||||
|
||||
const (
|
||||
//TextProperty represents text to write
|
||||
TextProperty Property = "text"
|
||||
)
|
||||
|
||||
func (t *text) enabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (t *text) string() string {
|
||||
textProperty := t.props.getString(TextProperty, "!!text property not defined!!")
|
||||
return textProperty
|
||||
}
|
||||
|
||||
func (t *text) init(props *properties, env environmentInfo) {
|
||||
t.props = props
|
||||
t.env = env
|
||||
}
|
29
segment_time.go
Normal file
29
segment_time.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type tempus struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
}
|
||||
|
||||
const (
|
||||
//TimeFormat uses the reference time Mon Jan 2 15:04:05 MST 2006 to show the pattern with which to format the current time
|
||||
TimeFormat Property = "time_format"
|
||||
)
|
||||
|
||||
func (t *tempus) enabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (t *tempus) string() string {
|
||||
timeFormatProperty := t.props.getString(TimeFormat, "15:04:05")
|
||||
return time.Now().Format(timeFormatProperty)
|
||||
}
|
||||
|
||||
func (t *tempus) init(props *properties, env environmentInfo) {
|
||||
t.props = props
|
||||
t.env = env
|
||||
}
|
40
segment_virtualenv.go
Normal file
40
segment_virtualenv.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type venv struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
venvName string
|
||||
}
|
||||
|
||||
const (
|
||||
//PythonIcon used to indicate a Python virtualenv is active
|
||||
PythonIcon Property = "python_icon"
|
||||
)
|
||||
|
||||
func (v *venv) string() string {
|
||||
return fmt.Sprintf("%s %s", v.props.getString(PythonIcon, "PYTHON:"), v.venvName)
|
||||
}
|
||||
|
||||
func (v *venv) init(props *properties, env environmentInfo) {
|
||||
v.props = props
|
||||
v.env = env
|
||||
}
|
||||
|
||||
func (v *venv) enabled() bool {
|
||||
venvVars := []string{
|
||||
"VIRTUAL_ENV",
|
||||
"CONDA_ENV_PATH",
|
||||
"CONDA_DEFAULT_ENV",
|
||||
}
|
||||
var venv string
|
||||
for _, venvVar := range venvVars {
|
||||
venv = v.env.getenv(venvVar)
|
||||
if venv != "" {
|
||||
v.venvName = base(venv, v.env)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
102
segment_virtualenv_test.go
Executable file
102
segment_virtualenv_test.go
Executable file
|
@ -0,0 +1,102 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type venvArgs struct {
|
||||
virtualEnvName string
|
||||
condaEnvName string
|
||||
condaDefaultName string
|
||||
pathSeparator string
|
||||
}
|
||||
|
||||
func newVenvArgs() *venvArgs {
|
||||
return &venvArgs{
|
||||
virtualEnvName: "",
|
||||
condaEnvName: "",
|
||||
condaDefaultName: "",
|
||||
pathSeparator: "/",
|
||||
}
|
||||
}
|
||||
|
||||
func bootStrapVenvTest(args *venvArgs) *venv {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("getenv", "VIRTUAL_ENV").Return(args.virtualEnvName)
|
||||
env.On("getenv", "CONDA_ENV_PATH").Return(args.condaEnvName)
|
||||
env.On("getenv", "CONDA_DEFAULT_ENV").Return(args.condaDefaultName)
|
||||
env.On("getPathSeperator", nil).Return(args.pathSeparator)
|
||||
venv := &venv{
|
||||
env: env,
|
||||
}
|
||||
return venv
|
||||
}
|
||||
|
||||
func TestVenvWriterDisabled(t *testing.T) {
|
||||
args := newVenvArgs()
|
||||
venv := bootStrapVenvTest(args)
|
||||
assert.False(t, venv.enabled(), "the virtualenv has no name")
|
||||
}
|
||||
|
||||
func TestVenvWriterEnabledWithVirtualEnv(t *testing.T) {
|
||||
args := newVenvArgs()
|
||||
args.virtualEnvName = "venv"
|
||||
venv := bootStrapVenvTest(args)
|
||||
assert.True(t, venv.enabled(), "the virtualenv has a name")
|
||||
}
|
||||
|
||||
func TestVenvWriterEnabledWithCondaEnvPath(t *testing.T) {
|
||||
args := newVenvArgs()
|
||||
args.condaEnvName = "venv"
|
||||
venv := bootStrapVenvTest(args)
|
||||
assert.True(t, venv.enabled(), "the virtualenv has a name")
|
||||
}
|
||||
|
||||
func TestVenvWriterEnabledWithCondaDefaultEnv(t *testing.T) {
|
||||
args := newVenvArgs()
|
||||
args.condaDefaultName = "venv"
|
||||
venv := bootStrapVenvTest(args)
|
||||
assert.True(t, venv.enabled(), "the virtualenv has a name")
|
||||
}
|
||||
|
||||
func TestVenvWriterEnabledWithTwoValidEnvs(t *testing.T) {
|
||||
args := newVenvArgs()
|
||||
args.virtualEnvName = "venv"
|
||||
args.condaDefaultName = "venv"
|
||||
venv := bootStrapVenvTest(args)
|
||||
assert.True(t, venv.enabled(), "the virtualenv has a name")
|
||||
}
|
||||
|
||||
func TestVenvWriterNameWithVirtualEnv(t *testing.T) {
|
||||
args := newVenvArgs()
|
||||
args.virtualEnvName = "venv"
|
||||
venv := bootStrapVenvTest(args)
|
||||
_ = venv.enabled()
|
||||
assert.Equal(t, "venv", venv.venvName)
|
||||
}
|
||||
|
||||
func TestVenvWriterNameWithCondaEnvPath(t *testing.T) {
|
||||
args := newVenvArgs()
|
||||
args.condaEnvName = "venv"
|
||||
venv := bootStrapVenvTest(args)
|
||||
_ = venv.enabled()
|
||||
assert.Equal(t, "venv", venv.venvName)
|
||||
}
|
||||
|
||||
func TestVenvWriterNameWithCondaDefaultEnv(t *testing.T) {
|
||||
args := newVenvArgs()
|
||||
args.condaDefaultName = "venv"
|
||||
venv := bootStrapVenvTest(args)
|
||||
_ = venv.enabled()
|
||||
assert.Equal(t, "venv", venv.venvName)
|
||||
}
|
||||
|
||||
func TestVenvWriterNameTrailingSlash(t *testing.T) {
|
||||
args := newVenvArgs()
|
||||
args.virtualEnvName = "venv/"
|
||||
venv := bootStrapVenvTest(args)
|
||||
_ = venv.enabled()
|
||||
assert.Equal(t, "venv", venv.venvName)
|
||||
}
|
123
settings.go
Executable file
123
settings.go
Executable file
|
@ -0,0 +1,123 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
)
|
||||
|
||||
//Settings holds all the theme for rendering the prompt
|
||||
type Settings struct {
|
||||
ConsoleBackgroundColor string `json:"console_background_color"`
|
||||
RightSegmentOffset int `json:"right_segment_offset"`
|
||||
EndSpaceEnabled bool `json:"end_space_enabled"`
|
||||
Blocks []*Block `json:"blocks"`
|
||||
}
|
||||
|
||||
//BlockType type of block
|
||||
type BlockType string
|
||||
|
||||
//BlockAlignment aligment of a Block
|
||||
type BlockAlignment string
|
||||
|
||||
const (
|
||||
//Prompt writes one or more Segments
|
||||
Prompt BlockType = "prompt"
|
||||
//LineBreak creates a line break in the prompt
|
||||
LineBreak BlockType = "line-break"
|
||||
//Left aligns left
|
||||
Left BlockAlignment = "left"
|
||||
//Right aligns right
|
||||
Right BlockAlignment = "right"
|
||||
)
|
||||
|
||||
//Block defines a part of the prompt with optional segments
|
||||
type Block struct {
|
||||
Type BlockType `json:"type"`
|
||||
Alignment BlockAlignment `json:"alignment"`
|
||||
PowerlineSeparator string `json:"powerline_separator"`
|
||||
InvertPowerlineSeparatorColor bool `json:"invert_powerline_separator_color"`
|
||||
LineOffset int `json:"line_offset"`
|
||||
Segments []*Segment `json:"segments"`
|
||||
}
|
||||
|
||||
//GetSettings returns the default configuration including possible user overrides
|
||||
func GetSettings(env environmentInfo) *Settings {
|
||||
defaultSettings := getDefaultSettings()
|
||||
settings := loadUserConfiguration(env)
|
||||
_ = mergo.Merge(settings, defaultSettings)
|
||||
return settings
|
||||
}
|
||||
|
||||
func loadUserConfiguration(env environmentInfo) *Settings {
|
||||
var settings Settings
|
||||
settingsFileLocation := fmt.Sprintf("%s/.go_my_psh", env.getenv("HOME"))
|
||||
if _, err := os.Stat(*env.getArgs().Config); !os.IsNotExist(err) {
|
||||
settingsFileLocation = *env.getArgs().Config
|
||||
}
|
||||
defaultSettings, err := os.Open(settingsFileLocation)
|
||||
defer func() {
|
||||
_ = defaultSettings.Close()
|
||||
}()
|
||||
if err != nil {
|
||||
return &settings
|
||||
}
|
||||
jsonParser := json.NewDecoder(defaultSettings)
|
||||
_ = jsonParser.Decode(&settings)
|
||||
return &settings
|
||||
}
|
||||
|
||||
func getDefaultSettings() *Settings {
|
||||
settings := &Settings{
|
||||
EndSpaceEnabled: true,
|
||||
ConsoleBackgroundColor: "#193549",
|
||||
Blocks: []*Block{
|
||||
{
|
||||
Type: Prompt,
|
||||
Alignment: Left,
|
||||
PowerlineSeparator: "",
|
||||
Segments: []*Segment{
|
||||
{
|
||||
Type: Root,
|
||||
Style: Powerline,
|
||||
Background: "#ffe9aa",
|
||||
Foreground: "#100e23",
|
||||
},
|
||||
{
|
||||
Type: Session,
|
||||
Style: Powerline,
|
||||
Background: "#ffffff",
|
||||
Foreground: "#100e23",
|
||||
},
|
||||
{
|
||||
Type: Path,
|
||||
Style: Powerline,
|
||||
Background: "#91ddff",
|
||||
Foreground: "#100e23",
|
||||
},
|
||||
{
|
||||
Type: Git,
|
||||
Style: Powerline,
|
||||
Background: "#95ffa4",
|
||||
Foreground: "#100e23",
|
||||
},
|
||||
{
|
||||
Type: Venv,
|
||||
Style: Powerline,
|
||||
Background: "#906cff",
|
||||
Foreground: "#100e23",
|
||||
},
|
||||
{
|
||||
Type: Exit,
|
||||
Style: Powerline,
|
||||
Background: "#ff8080",
|
||||
Foreground: "#ffffff",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return settings
|
||||
}
|
Loading…
Reference in a new issue