Skip to content

Commit

Permalink
convert spaces to tabs, start on shortcut stuff for deleting NT_CONSO…
Browse files Browse the repository at this point in the history
…LE_PROPS
  • Loading branch information
lukesampson committed Aug 20, 2013
1 parent b195e22 commit 39a4965
Show file tree
Hide file tree
Showing 17 changed files with 305 additions and 287 deletions.
2 changes: 1 addition & 1 deletion concfg.sublime-project
Expand Up @@ -9,6 +9,6 @@
"settings": {
"default_line_ending": "windows",
"tab_size": 4,
"translate_tabs_to_spaces": true
"translate_tabs_to_spaces": false
}
}
6 changes: 3 additions & 3 deletions lib/commands.ps1
@@ -1,13 +1,13 @@
function command_files {
gci ("$psscriptroot\..\libexec") | where { $_.name.endswith('.ps1') }
gci ("$psscriptroot\..\libexec") | where { $_.name.endswith('.ps1') }
}

function commands {
command_files | % { command_name $_ }
command_files | % { command_name $_ }
}

function command_name($filename) { $filename.name -replace '\.ps1$', '' }

function exec($cmd, $arguments) {
& ("$psscriptroot\..\libexec\$cmd.ps1") @arguments
& ("$psscriptroot\..\libexec\$cmd.ps1") @arguments
}
36 changes: 18 additions & 18 deletions lib/core.ps1
Expand Up @@ -7,27 +7,27 @@
$colors = 'black,dark_blue,dark_green,dark_cyan,dark_red,dark_magenta,dark_yellow,gray,dark_gray,blue,green,cyan,red,magenta,yellow,white'.split(',')

$map = @{
'FontFamily'=@('font_true_type', 'font_type')
'FaceName'=@('font_face', 'string')
'FontSize'=@('font_size', 'dim')
'FontWeight'=@('font_weight','int')
'CursorSize'=@('cursor_size','cursor')
'QuickEdit'=@('quick_edit', 'bool')
'ScreenBufferSize'=@('screen_buffer_size', 'dim')
'WindowSize'=@('window_size', 'dim')
'PopupColors'=@('popup_colors', 'fg_bg')
'ScreenColors'=@('screen_colors', 'fg_bg')
'FullScreen'=@('fullscreen','bool')
'HistoryBufferSize'=@('command_history_length','int')
'NumberOfHistoryBuffers'=@('num_history_buffers','int')
'InsertMode'=@('insert_mode','bool')
'LoadConIme'=@('load_console_IME','bool')
'FontFamily'=@('font_true_type', 'font_type')
'FaceName'=@('font_face', 'string')
'FontSize'=@('font_size', 'dim')
'FontWeight'=@('font_weight','int')
'CursorSize'=@('cursor_size','cursor')
'QuickEdit'=@('quick_edit', 'bool')
'ScreenBufferSize'=@('screen_buffer_size', 'dim')
'WindowSize'=@('window_size', 'dim')
'PopupColors'=@('popup_colors', 'fg_bg')
'ScreenColors'=@('screen_colors', 'fg_bg')
'FullScreen'=@('fullscreen','bool')
'HistoryBufferSize'=@('command_history_length','int')
'NumberOfHistoryBuffers'=@('num_history_buffers','int')
'InsertMode'=@('insert_mode','bool')
'LoadConIme'=@('load_console_IME','bool')
}
for($i=0;$i -lt $colors.length;$i++) {
$map.add("ColorTable$($i.tostring('00'))", @($colors[$i],'color'))
$map.add("ColorTable$($i.tostring('00'))", @($colors[$i],'color'))
}
$reverse_map = @{}
foreach($key in $map.keys) {
$name,$type = $map[$key]
$reverse_map.add($name, @($key,$type))
$name,$type = $map[$key]
$reverse_map.add($name, @($key,$type))
}
10 changes: 5 additions & 5 deletions lib/help.ps1
@@ -1,16 +1,16 @@
function usage($text) {
$text | sls '(?m)^# Usage: ([^\n]*)$' | % { "usage: " + $_.matches[0].groups[1].value }
$text | sls '(?m)^# Usage: ([^\n]*)$' | % { "usage: " + $_.matches[0].groups[1].value }
}

function summary($text) {
$text | sls '(?m)^# Summary: ([^\n]*)$' | % { $_.matches[0].groups[1].value }
$text | sls '(?m)^# Summary: ([^\n]*)$' | % { $_.matches[0].groups[1].value }
}

function help($text) {
$help_lines = $text | sls '(?ms)^# Help:(.(?!^[^#]))*' | % { $_.matches[0].value; }
$help_lines -replace '(?ms)^#\s?(Help: )?', ''
$help_lines = $text | sls '(?ms)^# Help:(.(?!^[^#]))*' | % { $_.matches[0].value; }
$help_lines -replace '(?ms)^#\s?(Help: )?', ''
}

function my_usage { # gets usage for the calling script
usage (gc $myInvocation.PSCommandPath -raw)
usage (gc $myInvocation.PSCommandPath -raw)
}
11 changes: 11 additions & 0 deletions lib/shortcut.ps1
@@ -0,0 +1,11 @@
function linksto($path, $target) {
if(!(test-path $path)) { return $false }
if($path -notmatch '\.lnk$') { return $false }

$path = "$(resolve-path $path)"

$shell = new-object -com wscript.shell -strict
$shortcut = $shell.createshortcut($path)

return $shortcut.targetpath -eq $target
}
86 changes: 43 additions & 43 deletions libexec/export.ps1
Expand Up @@ -6,57 +6,57 @@
param($path)

function decode($val, $type) {
switch($type) {
'bool' { [bool]$val }
'color' {
$bytes = [bitconverter]::getbytes($val)
[array]::reverse($bytes)
$int = [bitconverter]::toint32($bytes, 0)
switch($type) {
'bool' { [bool]$val }
'color' {
$bytes = [bitconverter]::getbytes($val)
[array]::reverse($bytes)
$int = [bitconverter]::toint32($bytes, 0)

'#' + $int.tostring('x8').substring(0,6)
}
'cursor' {
switch($val) {
0x19 { 'small' }
0x32 { 'medium' }
0x64 { 'large' }
}
}
'fg_bg' {
$hex = $val.tostring('x2')
$bg_i = [convert]::toint32($hex[0],16)
$fg_i = [convert]::toint32($hex[1],16)
$bg = $colors[$bg_i]
$fg = $colors[$fg_i]
"$fg,$bg"
}
'font_type' { ($val -gt 0) }
'int' { $val }
'string' { $val }
'dim' {
$bytes = [bitconverter]::getbytes($val)
$width = [bitconverter]::toint16($bytes[0..2], 0)
$height = [bitconverter]::toint16($bytes, 2)
"$($width)x$($height)"
}
}
'#' + $int.tostring('x8').substring(0,6)
}
'cursor' {
switch($val) {
0x19 { 'small' }
0x32 { 'medium' }
0x64 { 'large' }
}
}
'fg_bg' {
$hex = $val.tostring('x2')
$bg_i = [convert]::toint32($hex[0],16)
$fg_i = [convert]::toint32($hex[1],16)
$bg = $colors[$bg_i]
$fg = $colors[$fg_i]
"$fg,$bg"
}
'font_type' { ($val -gt 0) }
'int' { $val }
'string' { $val }
'dim' {
$bytes = [bitconverter]::getbytes($val)
$width = [bitconverter]::toint16($bytes[0..2], 0)
$height = [bitconverter]::toint16($bytes, 2)
"$($width)x$($height)"
}
}
}

function export_json {
$props = @{}
(gp hkcu:\console).psobject.properties | sort name |% {
$name,$type = $map[$_.name]
if($name) {
$props.add($name, (decode $_.value $type))
}
}
$props = @{}
(gp hkcu:\console).psobject.properties | sort name |% {
$name,$type = $map[$_.name]
if($name) {
$props.add($name, (decode $_.value $type))
}
}

$props | convertto-json
$props | convertto-json
}

$json = export_json
if($path) {
$json | out-file $path -encoding utf8
write-host "console settings exported to $(split-path $path -leaf)" -f darkgreen
$json | out-file $path -encoding utf8
write-host "console settings exported to $(split-path $path -leaf)" -f darkgreen
}
else { $json }
38 changes: 19 additions & 19 deletions libexec/help.ps1
Expand Up @@ -7,41 +7,41 @@ param($cmd)
. "$psscriptroot\..\lib\help.ps1"

function print_help($cmd) {
$file = gc ("$psscriptroot\$cmd.ps1") -raw
$file = gc ("$psscriptroot\$cmd.ps1") -raw

$usage = usage $file
$summary = summary $file
$help = help $file
$usage = usage $file
$summary = summary $file
$help = help $file

if($usage) { "$usage`n" }
if($help) { $help }
if($usage) { "$usage`n" }
if($help) { $help }
}

function print_summaries {
$commands = @{}
$commands = @{}

command_files | % {
$command = command_name $_
$summary = summary (gc ("$psscriptroot\$_") -raw )
if(!($summary)) { $summary = '' }
$commands.add("$command ", $summary) # add padding
}
command_files | % {
$command = command_name $_
$summary = summary (gc ("$psscriptroot\$_") -raw )
if(!($summary)) { $summary = '' }
$commands.add("$command ", $summary) # add padding
}

$commands.getenumerator() | sort name | ft -hidetablehead -autosize -wrap
$commands.getenumerator() | sort name | ft -hidetablehead -autosize -wrap
}

$commands = commands

if(!($cmd)) {
"usage: concfg <command> [<args]
"usage: concfg <command> [<args]
Some useful commands are:"
print_summaries
"type 'concfg help <command>' to get help for a specific command"
print_summaries
"type 'concfg help <command>' to get help for a specific command"
} elseif($commands -contains $cmd) {
print_help $cmd
print_help $cmd
} else {
"concfg help: no such command '$cmd'"; exit 1
"concfg help: no such command '$cmd'"; exit 1
}

exit 0
Expand Down

0 comments on commit 39a4965

Please sign in to comment.