Add PowerShell modules setup and Clink config
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
local function alias(short, long)
|
||||||
|
os.execute('doskey ' .. short .. '=' .. long)
|
||||||
|
end
|
||||||
|
|
||||||
|
alias('ls', 'dir $*')
|
||||||
|
alias('cat', 'bat $*')
|
||||||
|
alias('vi', 'nvim $*')
|
||||||
|
alias('rdp','mstsc /v:$*')
|
||||||
|
alias('grep', 'rg')
|
||||||
|
|
||||||
|
alias('jdk8home', 'set JAVA_HOME=%PROGRAMFILES%\\Java\\jdk-1.8')
|
||||||
|
alias('jdk8home32', 'set JAVA_HOME=C:\\Program Files (x86)\\Java\\jdk-1.8')
|
||||||
|
alias('jdk21home', 'set JAVA_HOME=%PROGRAMFILES%\\Java\\jdk-21')
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
# name: Selects default key bindings
|
||||||
|
# type: enum
|
||||||
|
# options: bash,windows
|
||||||
|
clink.default_bindings = windows
|
||||||
|
|
||||||
|
# name: Controls what startup logo to show
|
||||||
|
# type: enum
|
||||||
|
# options: none,full,short
|
||||||
|
clink.logo = none
|
||||||
|
|
||||||
|
# name: Pressing Ctrl-D exits session
|
||||||
|
# type: boolean
|
||||||
|
cmd.ctrld_exits = False
|
||||||
|
|
||||||
|
# name: Argument color
|
||||||
|
# type: color
|
||||||
|
color.arg = bold
|
||||||
|
|
||||||
|
# name: Argument info color
|
||||||
|
# type: color
|
||||||
|
color.arginfo = sgr 38;5;172
|
||||||
|
|
||||||
|
# name: Argmatcher color
|
||||||
|
# type: color
|
||||||
|
color.argmatcher = sgr 1;38;5;40
|
||||||
|
|
||||||
|
# name: Color for home dir tilde
|
||||||
|
# type: color
|
||||||
|
color.autoexpandtilde = bright cyan
|
||||||
|
|
||||||
|
# name: Shell command completions
|
||||||
|
# type: color
|
||||||
|
color.cmd = bold
|
||||||
|
|
||||||
|
# name: Color for < and > redirection symbols
|
||||||
|
# type: color
|
||||||
|
color.cmdredir = sgr 38;5;172
|
||||||
|
|
||||||
|
# name: Color for & and | command separators
|
||||||
|
# type: color
|
||||||
|
color.cmdsep = sgr 38;5;135
|
||||||
|
|
||||||
|
# name: Color for comment row
|
||||||
|
# type: color
|
||||||
|
color.comment_row = sgr 38;5;87;48;5;18
|
||||||
|
|
||||||
|
# name: Description completion color
|
||||||
|
# type: color
|
||||||
|
color.description = sgr 38;5;39
|
||||||
|
|
||||||
|
# name: Color for command divider line
|
||||||
|
# type: color
|
||||||
|
color.divider_line = sgr 30;48;5;25
|
||||||
|
|
||||||
|
# name: Color for command end divider line
|
||||||
|
# type: color
|
||||||
|
color.divider_line_end = sgr 38;5;25
|
||||||
|
|
||||||
|
# name: Doskey completions
|
||||||
|
# type: color
|
||||||
|
color.doskey = sgr 1;38;5;75
|
||||||
|
|
||||||
|
# name: Color for escape for plain tilde
|
||||||
|
# type: color
|
||||||
|
color.escapetilde = bright cyan on blue
|
||||||
|
|
||||||
|
# name: Color for executable command word
|
||||||
|
# type: color
|
||||||
|
color.executable = sgr 1;38;5;33
|
||||||
|
|
||||||
|
# name: Filtered completion color
|
||||||
|
# type: color
|
||||||
|
color.filtered = bold
|
||||||
|
|
||||||
|
# name: Flag color
|
||||||
|
# type: color
|
||||||
|
color.flag = sgr 38;5;117
|
||||||
|
|
||||||
|
# name: Hidden file completions
|
||||||
|
# type: color
|
||||||
|
color.hidden = sgr 38;5;160
|
||||||
|
|
||||||
|
# name: History expansion color
|
||||||
|
# type: color
|
||||||
|
color.histexpand = sgr 97;48;5;55
|
||||||
|
|
||||||
|
# name: Horizontal scroll marker color
|
||||||
|
# type: color
|
||||||
|
color.horizscroll = sgr 38;5;16;48;5;30
|
||||||
|
|
||||||
|
# name: Input text color
|
||||||
|
# type: color
|
||||||
|
color.input = sgr 38;5;214
|
||||||
|
|
||||||
|
# name: For user-interaction prompts
|
||||||
|
# type: color
|
||||||
|
color.interact = bold
|
||||||
|
|
||||||
|
# name: Color for 'rem lua:' prefix
|
||||||
|
# type: color
|
||||||
|
color.luaprefix = bright cyan on blue
|
||||||
|
|
||||||
|
# name: Message area color
|
||||||
|
# type: color
|
||||||
|
color.message = default
|
||||||
|
|
||||||
|
# name: Readonly file completions
|
||||||
|
# type: color
|
||||||
|
color.readonly = sgr 38;5;28
|
||||||
|
|
||||||
|
# name: Selected completion color
|
||||||
|
# type: color
|
||||||
|
color.selected_completion = sgr 7
|
||||||
|
|
||||||
|
# name: Selection color
|
||||||
|
# type: color
|
||||||
|
color.selection = sgr 38;5;16;48;5;179
|
||||||
|
|
||||||
|
# name: Unexpected argument color
|
||||||
|
# type: color
|
||||||
|
color.unexpected = default
|
||||||
|
|
||||||
|
# name: Color for unrecognized command word
|
||||||
|
# type: color
|
||||||
|
color.unrecognized = sgr 38;5;203
|
||||||
|
|
||||||
|
# name: The number of history lines to save
|
||||||
|
# type: integer
|
||||||
|
history.max_lines = 25000
|
||||||
|
|
||||||
|
# name: History item timestamps
|
||||||
|
# type: enum
|
||||||
|
# options: off,save,show
|
||||||
|
history.time_stamp = show
|
||||||
|
|
||||||
|
# name: Expand envvars when completing
|
||||||
|
# type: boolean
|
||||||
|
match.expand_envvars = True
|
||||||
|
|
||||||
|
# name: Try substring if no prefix matches
|
||||||
|
# type: boolean
|
||||||
|
match.substring = True
|
||||||
|
|
||||||
|
# name: Show a tip when Clink starts
|
||||||
|
# type: boolean
|
||||||
|
tips.enable = False
|
||||||
|
|
||||||
|
# name: Changes the prefix of the aliases
|
||||||
|
# type: string
|
||||||
|
zoxide.cmd = z
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
-- oh-my-posh.lua
|
||||||
|
load(io.popen('oh-my-posh.exe --config="C:/Users/reazul.ashraf/AppData/Local/Programs/oh-my-posh/themes/nordtron.omp.json" --init --shell cmd'):read("*a"))()
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
-- =============================================================================
|
||||||
|
--
|
||||||
|
-- Settings copied from 'zoxide init'. Run `clink set` to modify these options, e.g. `clink set zoxide.cmd f`
|
||||||
|
--
|
||||||
|
|
||||||
|
settings.add('zoxide.cmd', 'z', 'Changes the prefix of the aliases')
|
||||||
|
settings.add('zoxide.hook', { 'pwd', 'prompt', 'none' }, 'Changes when directory scores are incremented')
|
||||||
|
settings.add('zoxide.no_aliases', false, "Don't define aliases")
|
||||||
|
settings.add('zoxide.usepromptfilter', false, "Use clink promptfilter to hook even if onbeginedit is supported")
|
||||||
|
settings.add('zoxide.promptfilter_prio', -50, "Changes the priority of the promptfilter hook (only if usepromptfilter is true)")
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
--
|
||||||
|
-- Utility functions for zoxide.
|
||||||
|
--
|
||||||
|
|
||||||
|
-- Generate `cd` command
|
||||||
|
local function __zoxide_cd(dir)
|
||||||
|
if os.getenv '_ZO_ECHO' == '1' then
|
||||||
|
print(dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 'cd /d -' doesn't work for clink versions before v1.2.41 (https://github.com/chrisant996/clink/issues/191)
|
||||||
|
-- lastest cmder release (v1.3.18) uses clink v1.1.45
|
||||||
|
if dir == '-' and (clink.version_encoded or 0) < 10020042 then
|
||||||
|
return 'cd -'
|
||||||
|
end
|
||||||
|
|
||||||
|
return 'cd /d ' .. dir
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Run `zoxide query` and generate `cd` command from result
|
||||||
|
local function __zoxide_query(options, keywords)
|
||||||
|
options = table.concat(options, ' ')
|
||||||
|
keywords = table.concat(keywords, ' ')
|
||||||
|
|
||||||
|
local file = io.popen('zoxide query ' .. options .. ' -- ' .. keywords)
|
||||||
|
local result = file:read '*line'
|
||||||
|
local ok = file:close()
|
||||||
|
|
||||||
|
if ok then
|
||||||
|
return __zoxide_cd(result)
|
||||||
|
else
|
||||||
|
return 'call' -- no-op that just sets %ERRORLEVEL% to 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add directory to the database.
|
||||||
|
local function __zoxide_add(dir)
|
||||||
|
os.execute('zoxide add -- "' .. dir:gsub('^(.-)\\*$', '%1') .. '"')
|
||||||
|
end
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
--
|
||||||
|
-- Hook configuration for zoxide.
|
||||||
|
--
|
||||||
|
local __usepromptfilter = settings.get 'zoxide.usepromptfilter'
|
||||||
|
|
||||||
|
if not clink.onbeginedit then
|
||||||
|
__usepromptfilter = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local __zoxide_oldpwd
|
||||||
|
function __zoxide_hook()
|
||||||
|
local zoxide_hook = settings.get 'zoxide.hook'
|
||||||
|
|
||||||
|
if zoxide_hook == 'none' then
|
||||||
|
-- do nothing
|
||||||
|
return
|
||||||
|
elseif zoxide_hook == 'prompt' then
|
||||||
|
-- run `zoxide add` on every prompt
|
||||||
|
__zoxide_add(os.getcwd())
|
||||||
|
elseif zoxide_hook == 'pwd' then
|
||||||
|
-- run `zoxide add` when the working directory changes
|
||||||
|
local cwd = os.getcwd()
|
||||||
|
if __zoxide_oldpwd and __zoxide_oldpwd ~= cwd then
|
||||||
|
__zoxide_add(cwd)
|
||||||
|
end
|
||||||
|
__zoxide_oldpwd = cwd
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if __usepromptfilter then
|
||||||
|
local __promptfilter_prio = settings.get 'zoxide.promptfilter_prio'
|
||||||
|
local __zoxide_prompt = clink.promptfilter(__promptfilter_prio)
|
||||||
|
|
||||||
|
function __zoxide_prompt:filter()
|
||||||
|
__zoxide_hook()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
clink.onbeginedit(__zoxide_hook)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
--
|
||||||
|
-- Define aliases.
|
||||||
|
--
|
||||||
|
|
||||||
|
-- 'z' alias
|
||||||
|
local function __zoxide_z(keywords)
|
||||||
|
if #keywords == 0 then
|
||||||
|
return __zoxide_cd(os.getenv 'USERPROFILE')
|
||||||
|
elseif #keywords == 1 then
|
||||||
|
local keyword = keywords[1]
|
||||||
|
if keyword == '-' then
|
||||||
|
return __zoxide_cd '-'
|
||||||
|
elseif os.isdir(keyword) then
|
||||||
|
return __zoxide_cd(keyword)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local cwd = '"' .. os.getcwd() .. '"'
|
||||||
|
return __zoxide_query({ '--exclude', cwd }, keywords)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 'zi' alias
|
||||||
|
local function __zoxide_zi(keywords)
|
||||||
|
return __zoxide_query({ '--interactive' }, keywords)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
--
|
||||||
|
-- Clink input text filter.
|
||||||
|
--
|
||||||
|
|
||||||
|
local function onfilterinput(text)
|
||||||
|
args = string.explode(text, ' ', '"')
|
||||||
|
if #args == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- settings
|
||||||
|
zoxide_cmd = settings.get 'zoxide.cmd'
|
||||||
|
zoxide_no_aliases = settings.get 'zoxide.no_aliases'
|
||||||
|
|
||||||
|
-- edge case:
|
||||||
|
-- * zoxide command prefix is 'cd'
|
||||||
|
-- * clink converted 'cd -' -> 'cd /d "some_directory"'
|
||||||
|
local cd_regex = '^%s*cd%s+/d%s+"(.-)"%s*$'
|
||||||
|
if zoxide_cmd == 'cd' and text:match(cd_regex) then
|
||||||
|
if zoxide_no_aliases then
|
||||||
|
-- clink handles it
|
||||||
|
return
|
||||||
|
else
|
||||||
|
-- zoxide handles it
|
||||||
|
return __zoxide_cd(text:gsub(cd_regex, '%1')), false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmd = table.remove(args, 1)
|
||||||
|
if cmd == '__zoxide_z' or (cmd == zoxide_cmd and not zoxide_no_aliases) then
|
||||||
|
return __zoxide_z(args), false
|
||||||
|
elseif cmd == '__zoxide_zi' or (cmd == zoxide_cmd .. 'i' and not zoxide_no_aliases) then
|
||||||
|
return __zoxide_zi(args), false
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if clink.onfilterinput then
|
||||||
|
clink.onfilterinput(onfilterinput)
|
||||||
|
else
|
||||||
|
clink.onendedit(onfilterinput)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
--
|
||||||
|
-- To initalize zoxide, add this script to one of clink's lua script locations (e.g. zoxide.lua)
|
||||||
|
-- (see https://chrisant996.github.io/clink/clink.html#location-of-lua-scripts)
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
Write-Host "Checking for required PowerShell modules..."
|
||||||
|
|
||||||
|
$modules = @(
|
||||||
|
"posh-git",
|
||||||
|
"Profiler",
|
||||||
|
"PSFzf",
|
||||||
|
"PSProfiler",
|
||||||
|
"PSScriptAnalyzer",
|
||||||
|
"Terminal-Icons",
|
||||||
|
"gsudoModule"
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach ($mod in $modules) {
|
||||||
|
if (-not (Get-Module -ListAvailable -Name $mod)) {
|
||||||
|
Write-Host "Installing $mod..."
|
||||||
|
Install-Module $mod -Scope CurrentUser -Force -AllowClobber
|
||||||
|
} else {
|
||||||
|
Write-Host "$mod is already installed."
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user