MohSD

funcs.ps1

Nov 3rd, 2025
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 3.32 KB | Source Code | 0 0
  1. # prompt
  2. function prompt {
  3.   "$(Get-Date -format "dd/MM") - $(Get-Location)> "
  4. }
  5.  
  6. # log
  7. function loginfo([string]$message, [string] $title= "info") {
  8.   Write-Host -Foreground blue "$($title.ToUpper()): $message"
  9. }
  10. function logsuccess([string]$message, [string] $title= "success") {
  11.   Write-Host -Foreground green "$($title.ToUpper()): $message"
  12. }
  13. function logerror([string]$message, [string] $title= "error") {
  14.   Write-Host -Foreground red "$($title.ToUpper()): $message"
  15. }
  16. function errorlog {
  17.   $err= Get-Error
  18.   logerror "Oups ! An error occured πŸ˜”"
  19.   Write-Host "`n$($err.Exception.Message)`n"
  20.   Write-Host "$($err.InvocationInfo.PositionMessage)`n"
  21.   exit
  22. }
  23.  
  24. # git
  25. function gadd ([string] $files= "./") {
  26.   git add $files
  27. }
  28. function gcom ([string] $commit= "init"){
  29.   git commit -am $commit
  30. }
  31. function gpush {
  32.   git push
  33. }
  34. function gstat ([string] $files= "./") {
  35.   git status $files
  36. }
  37. function glog {
  38.   git log --oneline
  39. }
  40. function gdiff ([string] $files= "./") {
  41.   git diff $files
  42. }
  43. function gstats {
  44.   $directories= Get-Childitem -Directory
  45.   $i= 0
  46.  
  47.   foreach ($dir in $directories){
  48.     Set-Location $dir
  49.     if (Test-Path ".git") {
  50.       logsuccess $dir.Name "GIT"
  51.       git status
  52.       $i++
  53.     } else {
  54.       logerror $dir.Name "NOT GIT"
  55.     }
  56.     Set-Location "../"
  57.   }
  58.  
  59.   loginfo "$i/$($directories.Length) Git repositories"
  60. }
  61. function ginit {
  62.   git init
  63.   gadd
  64.   gcom
  65. }
  66.  
  67. # search
  68. function grep([string] $search, [string] $path= "./") {
  69.   Get-ChildItem -Recurse $path | Select-String $search
  70. }
  71. function search([string] $file, [string] $path= "./", [bool] $hidden= $false) {
  72.   if ($hidden) {
  73.     Get-Childitem -Recurse -Hidden $path | ? Name -match $file | % Fullname
  74.   } else {
  75.     Get-Childitem -Recurse $path | ? Name -match $file | % Fullname
  76.   }
  77. }
  78.  
  79. # time
  80. function today {
  81.   Get-Date -Format "dd-MM-yy"
  82. }
  83.  
  84. # file system
  85. function path {
  86.   Set-Clipboard $(Get-Location).Path
  87.   loginfo "Path copied"
  88. }
  89. function folder([string] $dir) {
  90.   if (Test-Path $dir) { return }
  91.   New-Item $dir -ItemType Directory
  92. }
  93. function getcp([string] $path, [bool] $inFolder= $false) {
  94.   $path= $path.Replace("/", "\")
  95.   $file= $(Get-Item $path).BaseName
  96.  
  97.   if (Test-Path $path -PathType Leaf) {
  98.     xcopy $path ".\" /s /i
  99.   } elseif (Test-Path $path -PathType Container) {
  100.     $inFolder ? $(xcopy $path ".\" /s /i) : $(xcopy $path $file /s /i)  
  101.   } else {
  102.     logerror "Error while copying $path"
  103.   }
  104. }
  105. function util([string[]] $files) {
  106.   foreach ($util in $files) {
  107.     if (getcp "$PRG\utils\$util") {
  108.       loginfo "Util $util copied"
  109.     }
  110.     else {
  111.       logerror "Error while copying $util"
  112.     }
  113.   }
  114. }
  115.  
  116. # network
  117. function lch([int] $port= 8080) {
  118.   Start-Process "http://localhost:$port"  
  119. }
  120.  
  121. # data
  122. function lorem([int] $count=1) {
  123.   $lorem= "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quis eos ipsum aut laudantium nihil aliquid, vel a odio eaque quisquam dignissimos quo. Beatae similique aspernatur ipsam, rerum expedita ducimus, dignissimos sapiente praesentium id velit sint, aliquid ab reprehenderit numquam? Dignissimos maxime provident molestiae veritatis rem eius ea labore expedita dolorem."
  124.   $res= ""
  125.  
  126.   for ($i= 0; $i -lt $count; $i++) {
  127.     $res+= "$lorem`n"
  128.   }
  129.  
  130.   Write-Output $res
  131.   Set-Clipboard $res  
  132. }
  133.  
Advertisement
Add Comment
Please, Sign In to add comment