diff --git a/Data/Abbr/computing.csv b/Data/Abbr/computing.csv index bf989b0b..2ec1549d 100644 --- a/Data/Abbr/computing.csv +++ b/Data/Abbr/computing.csv @@ -2611,7 +2611,8 @@ TPI,Total Profit Improvement TPM,Total Productive Maintenance TPM,Trusted Platform Module TPOP,Time-Phased Order Point -TPS,terminal proxy server +TPS,Terminal Proxy Server +TPU,Tensor Processing Unit TQC,Total Quality Control TQM,Total Quality Management TRI,Toxic Release Inventory diff --git a/Scripts/list-dir-tree.ps1 b/Scripts/list-dir-tree.ps1 index bcd69674..293cc617 100755 --- a/Scripts/list-dir-tree.ps1 +++ b/Scripts/list-dir-tree.ps1 @@ -2,21 +2,24 @@ .SYNOPSIS Lists a directory tree .DESCRIPTION - This PowerShell script lists all files and folders in a directory tree. -.PARAMETER DirTree + This PowerShell script lists all files and folders in a neat directory tree (including icon and size). +.PARAMETER Path Specifies the path to the directory tree .EXAMPLE - PS> ./list-dir-tree.ps1 C:\ + PS> ./list-dir-tree.ps1 C:\MyFolder + β”œπŸ“‚Results + β”‚ β”œπŸ“„sales.txt (442K) + (2 folders, 1 file, 442K total) .LINK https://github.com/fleschutz/PowerShell .NOTES Author: Markus Fleschutz | License: CC0 #> -param([string]$DirTree = "$PWD") +param([string]$Path = "$PWD") -function GetFileIcon { param([string]$Suffix) - switch ($Suffix) { +function GetFileIcon([string]$suffix) { + switch ($suffix) { ".csv" {return "πŸ“Š"} ".epub" {return "πŸ““"} ".exe" {return "βš™οΈ"} @@ -30,32 +33,43 @@ function GetFileIcon { param([string]$Suffix) } } -function ListDir { param([string]$Directory, [int]$Depth) - $Depth++ - $Items = Get-ChildItem -path $Directory - foreach($Item in $Items) { - $Filename = $Item.Name - for ($i = 1; $i -lt $Depth; $i++) { Write-Host "β”‚ " -noNewline } - if ($Item.Mode -like "d*") { - Write-Host "β”œ" -noNewline - Write-Host -foregroundColor green "πŸ“‚$Filename" - ListDir "$Directory\$Filename" $Depth - $global:Dirs++ +function Bytes2String([int64]$bytes) { + if ($bytes -lt 1000) { return "$bytes bytes" } + $bytes /= 1000 + if ($bytes -lt 1000) { return "$($bytes)K" } + $bytes /= 1000 + if ($bytes -lt 1000) { return "$($bytes)MB" } + $bytes /= 1000 + if ($bytes -lt 1000) { return "$($bytes)GB" } + $bytes /= 1000 + return "$($Bytes)TB" +} + +function ListDirectory([string]$path, [int]$depth) { + $depth++ + $items = Get-ChildItem -path $path + foreach($item in $items) { + $filename = $item.Name + for ($i = 1; $i -lt $depth; $i++) { Write-Host "β”‚ " -noNewline } + if ($item.Mode -like "d*") { + Write-Output "β”œπŸ“‚$Filename" + ListDirectory "$path\$filename" $depth + $global:folders++ } else { - $Icon = GetFileIcon $Item.Extension - Write-Host "β”œ$($Icon)$Filename ($($Item.Length) bytes)" - $global:Files++ - $global:Bytes += $Item.Length + $icon = GetFileIcon $item.Extension + Write-Output "β”œ$($icon)$filename ($(Bytes2String $item.Length))" + $global:files++ + $global:bytes += $item.Length } } } try { - [int]$global:Dirs = 1 - [int]$global:Files = 0 - [int]$global:Bytes = 0 - ListDir $DirTree 0 - " ($($global:Dirs) folders, $($global:Files) files, $($global:Bytes) bytes in total)" + [int]$global:folders = 1 + [int]$global:files = 0 + [int]$global:bytes = 0 + ListDirectory $Path 0 + Write-Output " ($($global:folders) folders, $($global:files) files, $(Bytes2String $global:bytes) total)" exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/Scripts/new-branch.ps1 b/Scripts/new-branch.ps1 index 1928b797..a706dd83 100755 --- a/Scripts/new-branch.ps1 +++ b/Scripts/new-branch.ps1 @@ -50,7 +50,7 @@ try { if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" } [int]$elapsed = $stopWatch.Elapsed.TotalSeconds - "βœ”οΈ Creating branch '$newBranch' in repo πŸ“‚$repoPathName (based on '$currentBranch') took $elapsed sec" + "βœ”οΈ Created new branch '$newBranch' in repo πŸ“‚$repoPathName (based on '$currentBranch', it took $elapsed sec)" exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/Scripts/switch-branch.ps1 b/Scripts/switch-branch.ps1 index 48323ff4..e3e505c1 100755 --- a/Scripts/switch-branch.ps1 +++ b/Scripts/switch-branch.ps1 @@ -52,7 +52,7 @@ try { if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" } [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds - "βœ”οΈ Switching repo πŸ“‚$RepoDirName to branch '$BranchName' took $Elapsed sec" + "βœ”οΈ Switched repo πŸ“‚$RepoDirName to branch '$BranchName' (in $Elapsed sec)" exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/Scripts/write-code.ps1 b/Scripts/write-code.ps1 index abf7c7fb..185b00cb 100755 --- a/Scripts/write-code.ps1 +++ b/Scripts/write-code.ps1 @@ -26,9 +26,9 @@ function GetRandomCodeLine { 0 { return $Tabs + "`$count = 0" } 1 { return $Tabs + "`$count++" } 2 { return $Tabs + "exit 0 # success" } - 3 { return $Tabs + "`$Files = Get-ChildItem C:" } + 3 { return $Tabs + "`$files = Get-ChildItem C:" } 4 { return $Tabs + "Start-Sleep -seconds 1" } - 5 { return $Tabs + "`$Generator = New-Object System-Random" } + 5 { return $Tabs + "`$generator = New-Object System-Random" } 6 { $global:Tabs = " "; return "} else {" } 7 { $global:Tabs = " "; return "} catch {" } 8 { $global:Tabs = " "; return "} elseif (`$count -eq 0) {" } @@ -39,21 +39,21 @@ function GetRandomCodeLine { 13 { return $Tabs + "return 1" } 14 { return $Tabs + "return 0" } 15 { return $Tabs + "Write-Progress `"Working...`" " } - 16 { return $Tabs + "[bool]`$KeepAlive = `$true" } + 16 { return $Tabs + "[bool]`$keepAlive = `$true" } 17 { return $Tabs + "# Copyright Β© 2023 write-code.ps1. All Rights Reserved." } 18 { $global:Tabs = " "; return "for ([int]`$i = 0; `$i -lt 42; `$i++) {" } - 19 { return $Tabs + "`$StopWatch = [system.diagnostics.stopwatch]::startNew()" } - 20 { return $Tabs + "[int]`$Elapsed = `$StopWatch.Elapsed.TotalSeconds" } + 19 { return $Tabs + "`$stopWatch = [system.diagnostics.stopwatch]::startNew()" } + 20 { return $Tabs + "[int]`$elapsed = `$stopWatch.Elapsed.TotalSeconds" } 21 { $global:Tabs = " "; return "if (`$count -eq 42) {" } 22 { $global:Tabs = " "; return "} finally {" } 23 { return $Tabs + "throw `"Can't open file`" " } 24 { return $Tabs + "Start-Sleep -milliseconds 42" } 25 { return $Tabs + "`$Choice = Read-Host `"Red or blue pill?`"" } - 26 { return $Tabs + "[int]`$Answer = 42" } + 26 { return $Tabs + "[int]`$answer = 42" } 27 { $global:Tabs = ""; return "}" } 28 { $global:Tabs = " "; return "try {" } - 29 { $global:Tabs = " "; return "foreach(`$Row in `$Table) {" } - 30 { $global:Tabs = " "; return "foreach(`$File in `$Files) {" } + 29 { $global:Tabs = " "; return "foreach(`$row in `$table) {" } + 30 { $global:Tabs = " "; return "foreach(`$file in `$files) {" } } }