summaryrefslogtreecommitdiff
path: root/powershell/user_profile.ps1
blob: 43cdf725bca1f0aacee53a1786ebb392b3591f76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#Prompt
#Import-Module posh-git
#Import-Module oh-my-posh
#Set-PoshPrompt default
$ENV:STARSHIP_CONFIG = "$HOME\.config\starship.toml"
Import-Module -Name Terminal-Icons
# Alias
Set-Alias vim nvim
Set-Alias ll ls
Set-Alias grep findstr
Set-Alias tig 'C:\Program Files\Git\usr\bin\tig.exe'
Set-Alias less 'C:\Program Files\Git\usr\bin\less.exe'
Set-Alias htop ntop
Set-Alias -Name lv -Value Love2D
Set-Alias guid New-Guid
Set-Alias exif 'C:\tools\exiftool(-k).exe'
Set-Alias -Name upload -Value UploadFile
Set-Alias -Name getwalls -Value GetWallPapers
Set-Alias -Name retrowave -Value PlayRetrowave

## Git Alias
Set-Alias g git
Set-Alias -Name gdiff -Value GitDiff
Set-Alias -Name branch -Value GitCurrentBranch
Set-Alias -Name gg -Value GitGui
Set-Alias -Name gbs -Value GitSearchBranch
Set-Alias -Name push -Value GitPush
Set-Alias -Name status -Value GitStatus
Set-Alias -Name pcb -Value PushCurrentBranch
Set-Alias -Name glm -Value GitLastMessage
Set-Alias -Name chbranch -Value GitChooseBranch

function GitDiff {
    $output = (git diff --stat) | Out-String
    if (!$output) {
        Write-Output "NONE"
    }
    else {
        Write-Output $output
    }
}

function GitCurrentBranch {
    $output = (git branch) | grep '*' | Out-String
    $branchName = $output -replace '[*?\{]', '' -replace "\s", ""
    Write-Output "`nCurrent Branch is: $branchName `n"
    if (($args.Length -gt 0) -and ($args[0] -eq "copy")) {
        Set-Clipboard -Value $branchName
        Write-Output "Branch Name Copied to Clipboard!`n"
    }
}

function GitGui {
    (git gui)
}

function GitSearchBranch {
    $output = (git branch) | grep $args[0] | Out-String
    Write-Output $output
}

function Love2D {
    (love . --console)
}

function GitPush {
    if (($args.Length -lt 2) -or ($args.Length -gt 2)) {
        Write-Output "Usage: push <origin> <branch>"
    }
    else {
        (git push -u $args[0] $args[1])
    }
}

function GitStatus {
    $output = (git diff --stat)
    Write-Output $output
}

function PushCurrentBranch {
    $branchName = (git branch --show-current)
    $originQuery = (git config --get remote.origin.url)
    (git push -u $originQuery $branchName)
}

function GitLastMessage {
    $output = (git log -1)
    Write-Output $output
}

function UploadFile {
    $fileName = $args[0]
    $output = (curl -F'file=@"'$fileName'"' https://0x0.st)
    Set-Clipboard -Value $output
    Write-Output $output
}

function GetWallPapers {
    $searchQuery = $args[0];
    $response = Invoke-RestMethod -URI https://wallhaven.cc/api/v1/search?q="$searchQuery"
    $currentFolder = Get-Location
    
    if ($response.data.Length -eq 0) {
        Write-Output "No Wallpapers found with the search term -> $searchQuery 😢"
    }
    else {
        $isFolderExists = Test-Path -Path "C:\Users\Indrajith\Pictures\wallpapers\wallhaven\$searchQuery"
        if ($isFolderExists -eq $false) {
            New-Item -ItemType Directory -Path "C:\Users\Indrajith\Pictures\wallpapers\wallhaven\$searchQuery"
        }
        Set-Location -Path "C:\Users\Indrajith\Pictures\wallpapers\wallhaven\$searchQuery"
        for (($i = 0); ($i -lt $response.data.Length); $i++) {
            $data = $response.data[$i]
            $currentId = $data.id
            $filePath = $data.path
            # Write-Output $currentId
            (curl $filePath --output "$currentId.jpg")
        }
        # Write-Output $response.data
        Set-Location -Path $currentFolder
    }
}

function GitChooseBranch {
    # requires charm.sh gum in path
    $branches = (git branch --format="%(refname:short)")
    # Write-Output $branches
    $selectedBranch = (gum choose $branches)
    Write-Output "Hello $selectedBranch"
}

function PlayRetrowave {
    # requires ffplay in path
    
    $response = Invoke-RestMethod -URI "http://retrowave.ru/api/v1/tracks?limit=50&cursor=0"
    $musicBaseUrl = "https://retrowave.ru"

    if ($response.body.tracks.Length -gt 0) {
        for (($i = 0); ($i -lt $response.body.tracks.Length); $i++) {
            $currentTrack = $response.body.tracks[$i]
            $currentTrackUrl = $currentTrack.streamUrl
            $jsonData = (ffprobe -v quiet -print_format json -show_format "$musicBaseUrl$currentTrackUrl") | ConvertFrom-Json
            $albumName = $jsonData.format.tags.title
            $artist = $jsonData.format.tags.artist
            # Write-Output "Now Playing : $albumName - $artist"
            $asciiText = (Invoke-RestMethod -URI https://asciified.thelicato.io/api?text="$albumName - $artist&font=Big")
            Write-Output $asciiText
            (ffplay $musicBaseUrl$currentTrackUrl -nodisp -autoexit -loglevel -8 )
            Clear-Host
        }
    }
}