Skip to content

Instantly share code, notes, and snippets.

@Sansui233
Last active January 29, 2024 08:05
Show Gist options
  • Save Sansui233/0451b8f7c354d600c4efa74fc284d39c to your computer and use it in GitHub Desktop.
Save Sansui233/0451b8f7c354d600c4efa74fc284d39c to your computer and use it in GitHub Desktop.
Make powershell command more unix-like.
Import-Module posh-git
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\pure.omp.json" | Invoke-Expression
Import-Module PSReadLine
Set-PSReadlineKeyHandler -Key "Ctrl+d" -Function ViExit
Set-PSReadLineKeyHandler -Key Ctrl+C -Function Copy
Set-PSReadLineKeyHandler -Key Ctrl+v -Function Paste
Set-PSReadLineOption -EditMode Emacs
Import-Module -Name Terminal-Icons
Invoke-Expression (& { (zoxide init powershell | Out-String) })
# unix ls
function List {
param( $Path = '.' )
Get-ChildItem $Path | Format-Wide -Column 5
}
# unix which
function GetWhere {
param
(
$Cmd = ''
)
Get-Command -Name $Cmd
}
# unix open
function OpenCurrentFolder {
param
(
$Path = '.'
)
Invoke-Item $Path
}
# unix ln, please install gsudo for softlink requires admin
function ln {
# Write-Host("Hello {0} {1}!" -f $args[0], $args[1])
if ($args[2]) {
if ($args[0] -eq '-s') {
Write-Host "Making symbolic link"
gsudo
$absoluteTarget = Convert-Path $args[1]
New-Item -ItemType SymbolicLink -Path $args[2] -Target $absoluteTarget
}
else {
Write-Host "Invalid parameters for symbolic link creation. Use ln -s [target] [link]"
}
}
elseif ($args[0] -and $args[1]) {
Write-Host "Making hard link"
$absoluteTarget = Convert-Path $args[0]
New-Item -ItemType HardLink -Path $args[1] -Target $absoluteTarget
}
else {
Write-Host "Invalid number of parameters. Use ln [-s] [target] [link]"
}
}
new-alias which GetWhere
Set-Alias -Name ls -Value List -Option AllScope
new-alias ll dir
new-alias open OpenCurrentFolder
new-alias bash 'C:\Program Files\Git\bin\bash.exe'
new-alias grep findstr # it's better to install rg
new-alias vim nvim
# Proxy Togglers
function proxy {
$portInUse = netstat -ano | findstr "LISTENING" | findstr "7890"
$portInUse2 = netstat -ano | findstr "LISTENING" | findstr "10808"
if ($portInUse -ne $null) {
$env:HTTP_PROXY = "socks5://127.0.0.1:7890"
$env:HTTPS_PROXY = "socks5://127.0.0.1:7890"
Write-Host "Proxy set to socks port 7890"
} elseif ($portInUse2 -ne $null) {
$env:HTTP_PROXY = "socks5://127.0.0.1:10808"
$env:HTTPS_PROXY = "socks5://127.0.0.1:10808"
Write-Host "Proxy set to socks port 10808"
} else {
$env:HTTP_PROXY = "socks5://127.0.0.1:1080"
$env:HTTPS_PROXY = "socks5://127.0.0.1:1080"
Write-Host "Proxy set to socks port "
}
}
@{
Name = 'onehalf_dark'
Types = @{
Directories = @{
symlink = '6272a4'
junction = '6272a4'
WellKnown = @{
docs = '61AFEF'
documents = '61AFEF'
desktop = '61AFEF'
benchmark = 'E5C07B'
demo = 'C678DD'
samples = 'C678DD'
contacts = '61AFEF'
apps = 'E06C75'
applications = 'E06C75'
artifacts = 'E5C07B'
shortcuts = 'E06C75'
links = 'E06C75'
fonts = 'E06C75'
images = '98C379'
photos = '98C379'
pictures = '98C379'
videos = 'E5C07B'
movies = 'E5C07B'
media = 'DCDFE4'
music = '56B6C2'
songs = '56B6C2'
onedrive = 'DCDFE4'
downloads = 'DCDFE4'
src = '98C379'
development = '98C379'
projects = '98C379'
bin = '61AFEF'
tests = '61AFEF'
windows = '61AFEF'
users = 'DCDFE4'
favorites = 'E5C07B'
output = '98C379'
'.config' = '98C379'
'.cache' = '98C379'
'.vscode' = '61AFEF'
'.vscode-insiders' = '61AFEF'
'.git' = 'E06C75'
'.github' = 'DCDFE4'
'github' = 'DCDFE4'
'node_modules' = '98C379'
'.terraform' = '6272a4'
'.azure' = '61AFEF'
'.aws' = 'E5C07B'
'.kube' = '6272a4'
'.docker' = '6272a4'
}
}
Files = @{
symlink = '6272a4'
junction = '6272a4'
WellKnown = @{
'.gitattributes' = 'E06C75'
'.gitconfig' = 'E06C75'
'.gitignore' = 'E06C75'
'.gitmodules' = 'E06C75'
'.gitkeep' = 'E06C75'
'git-history' = 'E06C75'
'LICENSE' = 'E06C75'
'LICENSE.md' = 'E06C75'
'LICENSE.txt' = 'E06C75'
'CHANGELOG.md' = '98C379'
'CHANGELOG.txt' = '98C379'
'CHANGELOG' = '98C379'
'README.md' = '61AFEF'
'README.txt' = '61AFEF'
'README' = '61AFEF'
'.DS_Store' = '44475a'
'.tsbuildinfo' = 'E5C07B'
'.jscsrc' = 'E5C07B'
'.jshintrc' = 'E5C07B'
'tsconfig.json' = 'E5C07B'
'tslint.json' = 'E5C07B'
'composer.lock' = 'E5C07B'
'.jsbeautifyrc' = 'E5C07B'
'.esformatter' = 'E5C07B'
'cdp.pid' = 'E5C07B'
'.htaccess' = '98C379'
'.jshintignore' = '61AFEF'
'.buildignore' = '61AFEF'
'.mrconfig' = '61AFEF'
'.yardopts' = '61AFEF'
'manifest.mf' = '61AFEF'
'.clang-format' = '61AFEF'
'.clang-tidy' = '61AFEF'
'favicon.ico' = 'E5C07B'
'.travis.yml' = 'E5C07B'
'.gitlab-ci.yml' = 'E06C75'
'.jenkinsfile' = '6272a4'
'jenkinsfile' = '6272a4'
'bitbucket-pipelines.yml' = '61AFEF'
'bitbucket-pipelines.yaml' = '61AFEF'
'.azure-pipelines.yml' = '61AFEF'
'makefile' = '6272a4'
#
# Firebase
'firebase.json' = 'E5C07B'
'.firebaserc' = 'E5C07B'
# Bower
'.bowerrc' = 'E06C75'
'bower.json' = 'E06C75'
# Conduct
'code_of_conduct.md' = 'DCDFE4'
'code_of_conduct.txt' = 'DCDFE4'
# Docker
'Dockerfile' = '6272a4'
'docker-compose.yml' = '6272a4'
'docker-compose.yaml' = '6272a4'
'docker-compose.dev.yml' = '6272a4'
'docker-compose.local.yml' = '6272a4'
'docker-compose.ci.yml' = '6272a4'
'docker-compose.override.yml' = '6272a4'
'docker-compose.staging.yml' = '6272a4'
'docker-compose.prod.yml' = '6272a4'
'docker-compose.production.yml' = '6272a4'
'docker-compose.test.yml' = '6272a4'
# Vue
'vue.config.js' = '44475a'
'vue.config.ts' = '44475a'
# Gulp
'gulpfile.js' = 'E06C75'
'gulpfile.ts' = 'E06C75'
'gulpfile.babel.js' = 'E06C75'
'gruntfile.js' = 'E06C75'
# NodeJS
'package.json' = '98C379'
'package-lock.json' = '98C379'
'.nvmrc' = '98C379'
'.esmrc' = '98C379'
# NPM
'.nmpignore' = '61AFEF'
'.npmrc' = '61AFEF'
# Authors
'authors' = 'E06C75'
'authors.md' = 'E06C75'
'authors.txt' = 'E06C75'
# Terraform
'.terraform.lock.hcl' = '6272a4'
# Gradle
'gradlew' = '98C379'
}
# Archive files
'.7z' = 'E5C07B'
'.bz' = 'E5C07B'
'.tar' = 'E5C07B'
'.zip' = 'E5C07B'
'.gz' = 'E5C07B'
'.xz' = 'E5C07B'
'.br' = 'E5C07B'
'.bzip2' = 'E5C07B'
'.gzip' = 'E5C07B'
'.brotli' = 'E5C07B'
'.rar' = 'E5C07B'
'.tgz' = 'E5C07B'
# Executable things
'.bat' = '98C379'
'.cmd' = '98C379'
'.exe' = '61AFEF'
'.pl' = 'C678DD'
'.sh' = 'E06C75'
# App Packages
'.msi' = 'E5C07B'
'.msix' = 'E5C07B'
'.msixbundle' = 'E5C07B'
'.appx' = 'E5C07B'
'.AppxBundle' = 'E5C07B'
'.deb' = 'E5C07B'
'.rpm' = 'E5C07B'
# PowerShell
'.ps1' = '61AFEF'
'.psm1' = '61AFEF'
'.psd1' = '61AFEF'
'.ps1xml' = '61AFEF'
'.psc1' = '61AFEF'
'.pssc' = '61AFEF'
# Javascript
'.js' = 'E5C07B'
'.esx' = 'E5C07B'
'.mjs' = 'E5C07B'
# Java
'.java' = 'E5C07B'
'.jar' = 'E5C07B'
'.gradle' = '98C379'
# Python
'.py' = '6272a4'
'.ipynb' = '6272a4'
# React
'.jsx' = '6272a4'
'.tsx' = '6272a4'
# Typescript
'.ts' = 'E5C07B'
# Not-executable code files
'.dll' = '61AFEF'
# Importable Data files
'.clixml' = '61AFEF'
'.csv' = '98C379'
'.tsv' = '98C379'
# Settings
'.ini' = '6272a4'
'.dlc' = '6272a4'
'.config' = '6272a4'
'.conf' = '6272a4'
'.properties' = '6272a4'
'.prop' = '6272a4'
'.settings' = '6272a4'
'.option' = '6272a4'
'.reg' = '6272a4'
'.props' = '6272a4'
'.toml' = '6272a4'
'.prefs' = '6272a4'
'.sln.dotsettings' = '6272a4'
'.sln.dotsettings.user' = '6272a4'
'.cfg' = '6272a4'
# Source Files
'.c' = 'DCDFE4'
'.cpp' = 'DCDFE4'
'.cxx' = 'DCDFE4'
'.c++' = 'DCDFE4'
'.go' = '6272a4'
'.php' = 'C678DD'
# Visual Studio
'.csproj' = '56B6C2'
'.ruleset' = '56B6C2'
'.sln' = '56B6C2'
'.slnf' = '56B6C2'
'.suo' = '56B6C2'
'.vb' = '56B6C2'
'.vbs' = '56B6C2'
'.vcxitems' = '56B6C2'
'.vcxitems.filters' = '56B6C2'
'.vcxproj' = '56B6C2'
'.vsxproj.filters' = '56B6C2'
# CSharp
'.cs' = '6272a4'
'.csx' = '6272a4'
# Haskell
'.hs' = 'C678DD'
# XAML
'.xaml' = '61AFEF'
# Rust
'.rs' = 'E06C75'
# Database
'.pdb' = 'E5C07B'
'.sql' = 'E5C07B'
'.pks' = 'E5C07B'
'.pkb' = 'E5C07B'
'.accdb' = 'E5C07B'
'.mdb' = 'E5C07B'
'.sqlite' = 'E5C07B'
'.pgsql' = 'E5C07B'
'.postgres' = 'E5C07B'
'.psql' = 'E5C07B'
'.db' = 'E5C07B'
# Source Control
'.patch' = 'E06C75'
# Project files
'.user' = '61AFEF'
'.code-workspace' = '61AFEF'
# Text data files
'.log' = 'E5C07B'
'.txt' = '61AFEF'
# Subtitle files
'.srt' = '61AFEF'
'.lrc' = '61AFEF'
'.ass' = 'E06C75'
# HTML/css
'.html' = 'E06C75'
'.htm' = 'E06C75'
'.xhtml' = 'E06C75'
'.html_vm' = 'E06C75'
'.asp' = 'E06C75'
'.css' = '61AFEF'
'.sass' = '56B6C2'
'.scss' = '56B6C2'
'.less' = '98C379'
# Markdown
'.md' = '61AFEF'
'.markdown' = '61AFEF'
'.rst' = '61AFEF'
# Handlebars
'.hbs' = 'E5C07B'
# JSON
'.json' = 'E5C07B'
'.tsbuildinfo' = 'E5C07B'
# YAML
'.yml' = 'E06C75'
'.yaml' = 'E06C75'
# LUA
'.lua' = '61AFEF'
# Clojure
'.clj' = '98C379'
'.cljs' = '98C379'
'.cljc' = '98C379'
# Groovy
'.groovy' = '61AFEF'
# Vue
'.vue' = '6272a4'
# Dart
'.dart' = '6272a4'
# Elixir
'.ex' = 'E5C07B'
'.exs' = 'E5C07B'
'.eex' = 'E5C07B'
'.leex' = 'E5C07B'
# Erlang
'.erl' = 'E06C75'
# Elm
'.elm' = 'C678DD'
# Applescript
'.applescript' = '6272a4'
# XML
'.xml' = '98C379'
'.plist' = '98C379'
'.xsd' = '98C379'
'.dtd' = '98C379'
'.xsl' = '98C379'
'.xslt' = '98C379'
'.resx' = '98C379'
'.iml' = '98C379'
'.xquery' = '98C379'
'.tmLanguage' = '98C379'
'.manifest' = '98C379'
'.project' = '98C379'
# Documents
'.chm' = '61AFEF'
'.pdf' = 'E06C75'
# Excel
'.xls' = '98C379'
'.xlsx' = '98C379'
# PowerPoint
'.pptx' = 'E06C75'
'.ppt' = 'E06C75'
'.pptm' = 'E06C75'
'.potx' = 'E06C75'
'.potm' = 'E06C75'
'.ppsx' = 'E06C75'
'.ppsm' = 'E06C75'
'.pps' = 'E06C75'
'.ppam' = 'E06C75'
'.ppa' = 'E06C75'
# Word
'.doc' = '61AFEF'
'.docx' = '61AFEF'
'.rtf' = '61AFEF'
# Audio
'.mp3' = '56B6C2'
'.flac' = '56B6C2'
'.m4a' = '56B6C2'
'.wma' = '56B6C2'
'.aiff' = '56B6C2'
'.wav' = '56B6C2'
'.aac' = '56B6C2'
'.opus' = '56B6C2'
# Images
'.png' = '6272a4'
'.jpeg' = '6272a4'
'.jpg' = '6272a4'
'.gif' = '6272a4'
'.ico' = '6272a4'
'.tif' = '6272a4'
'.tiff' = '6272a4'
'.psd' = '6272a4'
'.psb' = '6272a4'
'.ami' = '6272a4'
'.apx' = '6272a4'
'.bmp' = '6272a4'
'.bpg' = '6272a4'
'.brk' = '6272a4'
'.cur' = '6272a4'
'.dds' = '6272a4'
'.dng' = '6272a4'
'.eps' = '6272a4'
'.exr' = '6272a4'
'.fpx' = '6272a4'
'.gbr' = '6272a4'
'.jbig2' = '6272a4'
'.jb2' = '6272a4'
'.jng' = '6272a4'
'.jxr' = '6272a4'
'.pbm' = '6272a4'
'.pgf' = '6272a4'
'.pic' = '6272a4'
'.raw' = '6272a4'
'.webp' = '6272a4'
'.svg' = 'E5C07B'
# Video
'.webm' = 'E5C07B'
'.mkv' = 'E5C07B'
'.flv' = 'E5C07B'
'.vob' = 'E5C07B'
'.ogv' = 'E5C07B'
'.ogg' = 'E5C07B'
'.gifv' = 'E5C07B'
'.avi' = 'E5C07B'
'.mov' = 'E5C07B'
'.qt' = 'E5C07B'
'.wmv' = 'E5C07B'
'.yuv' = 'E5C07B'
'.rm' = 'E5C07B'
'.rmvb' = 'E5C07B'
'.mp4' = 'E5C07B'
'.mpg' = 'E5C07B'
'.mp2' = 'E5C07B'
'.mpeg' = 'E5C07B'
'.mpe' = 'E5C07B'
'.mpv' = 'E5C07B'
'.m2v' = 'E5C07B'
# Email
'.ics' = '61AFEF'
# Certifactes
'.cer' = 'E06C75'
'.cert' = 'E06C75'
'.crt' = 'E06C75'
'.pfx' = 'E06C75'
# Keys
'.pem' = '61AFEF'
'.pub' = '61AFEF'
'.key' = '61AFEF'
'.asc' = '61AFEF'
'.gpg' = '61AFEF'
# Fonts
'.woff' = 'E06C75'
'.woff2' = 'E06C75'
'.ttf' = 'E06C75'
'.eot' = 'E06C75'
'.suit' = 'E06C75'
'.otf' = 'E06C75'
'.bmap' = 'E06C75'
'.fnt' = 'E06C75'
'.odttf' = 'E06C75'
'.ttc' = 'E06C75'
'.font' = 'E06C75'
'.fonts' = 'E06C75'
'.sui' = 'E06C75'
'.ntf' = 'E06C75'
'.mrg' = 'E06C75'
# Ruby
'.rb' = 'E06C75'
'.erb' = 'E06C75'
'.gemfile' = 'E06C75'
'Rakefile' = 'E06C75'
# FSharp
'.fs' = '61AFEF'
'.fsx' = '61AFEF'
'.fsi' = '61AFEF'
'.fsproj' = '61AFEF'
# Docker
'.dockerignore' = '6272a4'
'.dockerfile' = '6272a4'
# VSCode
'.vscodeignore' = '6272a4'
'.vsixmanifest' = '6272a4'
'.vsix' = '6272a4'
'.code-workplace' = '6272a4'
# Sublime
'.sublime-project' = 'E5C07B'
'.sublime-workspace' = 'E5C07B'
'.lock' = 'E5C07B'
# Terraform
'.tf' = '6272a4'
'.tfvars' = '6272a4'
'.auto.tfvars' = '6272a4'
# Bicep
'.bicep' = '61AFEF'
# Disk Image
'.vmdk' = 'DCDFE4'
'.vhd' = 'DCDFE4'
'.vhdx' = 'DCDFE4'
'.img' = 'DCDFE4'
'.iso' = 'DCDFE4'
# R language
'.R' = '6272a4'
'.Rmd' = '6272a4'
'.Rproj' = '6272a4'
# Julia language
'.jl' = '9259a3'
# Vim
'.vim' = '98C379'
# Puppet
'.pp' = 'E5C07B'
'.epp' = 'E5C07B'
# Scala
'.scala' = 'E06C75'
'.sc' = 'E06C75'
'.sbt' = 'E06C75'
# Autodesk Inventor
'.iLogicVb' = 'E06C75'
'.svelte' = 'E06C75'
}
}
}
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"foreground": "#BF616A",
"style": "plain",
"template": "{{ .UserName }} ",
"type": "session"
},
{
"foreground": "#81A1C1",
"properties": {
"style": "full"
},
"style": "plain",
"template": "{{ .Path }} ",
"type": "path"
}
],
"type": "prompt"
},
{
"alignment": "left",
"segments": [
{
"foreground": "#73bdb1",
"properties": {
"branch_ahead_icon": "<#88C0D0>\u21e1 </>",
"branch_behind_icon": "<#88C0D0>\u21e3 </>",
"branch_icon": "\ue725 ",
"fetch_stash_count": true,
"fetch_status": true,
"fetch_upstream_icon": true,
"github_icon": "",
"commit_icon": "\uf417 ",
"merge_icon": "\ue727 ",
"no_commits_icon": "\uf0c3 ",
"rebase_icon": "\ue728 ",
"revert_icon": "\uf0e2 ",
"tag_icon": "\uf412 "
},
"style": "plain",
"template": "{{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }}<#FFAFD7>*</>{{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \ueb4b {{ .StashCount }}{{ end }} ",
"type": "git"
}
],
"type": "prompt"
},
{
"alignment": "left",
"segments": [
{
"foreground": "#A3BE8C",
"properties": {
"style": "austin"
},
"style": "plain",
"template": " {{ .FormattedMs }} ",
"type": "executiontime"
}
],
"type": "prompt"
},
{
"alignment": "right",
"type": "prompt",
"segments": [
{
"type": "python",
"style": "plain",
"foreground": "#b6cae0",
"template": " \uE235 {{ if .Venv }}{{ .Venv }}{{ end }}",
"properties": {
"display_mode": "environment",
"fetch_virtual_env": true,
"home_enabled": true
}
},
{
"type": "node",
"style": "plain",
"foreground": "#b6cae0",
"template": " \ue718 {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }}",
"properties": {
"display_mode": "environment",
"fetch_virtual_env": true,
"home_enabled": true
}
}
]
},
{
"alignment": "left",
"newline": true,
"segments": [
{
"foreground": "#B48EAD",
"foreground_templates": [
"{{ if gt .Code 0 }}#BF616A{{ end }}"
],
"properties": {
"always_enabled": true
},
"style": "plain",
"template": "\u276f ",
"type": "exit"
}
],
"type": "prompt"
}
],
"console_title_template": "{{if .Root}}(Admin){{end}} {{.PWD}}",
"transient_prompt": {
"foreground": "#B48EAD",
"foreground_templates": [
"{{ if gt .Code 0 }}#BF616A{{ end }}"
],
"template": "\u276f "
},
"version": 2
}
@Sansui233
Copy link
Author

Sansui233 commented Mar 12, 2023

Powereshell Config Guide:

  1. Install the latest Powershell Core
  2. Install git-bash for basic bash and sh tools
  3. Install Windows Terminal and open Powershell
  4. Install PSReadLine
  5. Install posh-git
  6. Install oh-my-posh for showing extra info in term.
  7. Install gsudo for softlink
  8. open $PROFILE in powershell, append the contents of this config

Extra:
terminal icon theme path: ~\Documents\PowerShell\Modules\Terminal-Icons\0.11.0\Data\colorThemes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment