# prompt
function prompt {
"$(Get-Date -format "dd/MM") - $(Get-Location)> "
}
# log
function loginfo([string]$message, [string] $title= "info") {
Write-Host -Foreground blue "$($title.ToUpper()): $message"
}
function logsuccess([string]$message, [string] $title= "success") {
Write-Host -Foreground green "$($title.ToUpper()): $message"
}
function logerror([string]$message, [string] $title= "error") {
Write-Host -Foreground red "$($title.ToUpper()): $message"
}
function errorlog {
$err= Get-Error
logerror "Oups ! An error occured 😔"
Write-Host "`n$($err.Exception.Message)`n"
Write-Host "$($err.InvocationInfo.PositionMessage)`n"
exit
}
# git
function gadd ([string] $files= "./") {
git add $files
}
function gcom ([string] $commit= "init"){
git commit -am $commit
}
function gpush {
git push
}
function gstat ([string] $files= "./") {
git status $files
}
function glog {
git log --oneline
}
function gdiff ([string] $files= "./") {
git diff $files
}
function gstats {
$directories= Get-Childitem -Directory
$i= 0
foreach ($dir in $directories){
Set-Location $dir
if (Test-Path ".git") {
logsuccess $dir.Name "GIT"
git status
$i++
} else {
logerror $dir.Name "NOT GIT"
}
Set-Location "../"
}
loginfo "$i/$($directories.Length) Git repositories"
}
function ginit {
git init
gadd
gcom
}
# search
function grep([string] $search, [string] $path= "./") {
Get-ChildItem -Recurse $path | Select-String $search
}
function search([string] $file, [string] $path= "./", [bool] $hidden= $false) {
if ($hidden) {
Get-Childitem -Recurse -Hidden $path | ? Name -match $file | % Fullname
} else {
Get-Childitem -Recurse $path | ? Name -match $file | % Fullname
}
}
# time
function today {
Get-Date -Format "dd-MM-yy"
}
# file system
function path {
Set-Clipboard $(Get-Location).Path
loginfo "Path copied"
}
function folder([string] $dir) {
if (Test-Path $dir) { return }
New-Item $dir -ItemType Directory
}
function getcp([string] $path, [bool] $inFolder= $false) {
$path= $path.Replace("/", "\")
$file= $(Get-Item $path).BaseName
if (Test-Path $path -PathType Leaf) {
xcopy $path ".\" /s /i
} elseif (Test-Path $path -PathType Container) {
$inFolder ? $(xcopy $path ".\" /s /i) : $(xcopy $path $file /s /i)
} else {
logerror "Error while copying $path"
}
}
function util([string[]] $files) {
foreach ($util in $files) {
if (getcp "$PRG\utils\$util") {
loginfo "Util $util copied"
}
else {
logerror "Error while copying $util"
}
}
}
# network
function lch([int] $port= 8080) {
Start-Process "http://localhost:$port"
}
# data
function lorem([int] $count=1) {
$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."
$res= ""
for ($i= 0; $i -lt $count; $i++) {
$res+= "$lorem`n"
}
Write-Output $res
Set-Clipboard $res
}