Skip to content

Commit

Permalink
fix: alert, isfile, new, play, y22, ydl, yda, beep, ls; add: deploy, …
Browse files Browse the repository at this point in the history
…basename, open, mkvid
  • Loading branch information
kendfss committed Oct 19, 2024
1 parent c2d7687 commit a6d2e60
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 27 deletions.
36 changes: 36 additions & 0 deletions .profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Aliases
# set-alias lyx "C:\Program Files (x86)\LyX 2.3\bin\LyX.exe"
set-alias edge "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
# set-alias curl "C:\ProgramData\chocolatey\bin\curl.exe"
set-alias vlc "C:\Program Files\VideoLAN\VLC\vlc.exe"
# set-alias py38 "E:\Languages\Python38-64\python.exe"
set-alias firefox "C:\Program Files\Mozilla Firefox\firefox.exe"
# set-alias pm "F:\Programs\Workstations\FL Studio 20.8.1\System\Tools\Plugin Manager\PluginManager.exe"
set-alias chrome "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
set-alias -option AllScope cls "c:/shellpower/cls.ps1"
# set-alias gw "ghostwriter.exe"
set-alias envars "SystemPropertiesAdvanced.exe"
# set-alias sublime "E:\IDEs\Sublime Text 3\sublime_text.exe"
# set-alias brython brython-cli
# set-alias ptp ptpython
# set-alias sumatra "C:\Program Files\SumatraPDF\SumatraPDF.exe"
set-alias c set-clipboard
set-alias p get-clipboard
set-alias editor (where.exe hx)
# set-alias make "C:\msys64\usr\bin\make.exe"
set-alias s select
set-alias touch "C:\Program Files\Git\usr\bin\touch.exe"
set-alias grep "C:\Program Files\Git\usr\bin\grep.exe"
set-alias gbash "C:\Program Files\Git\git-bash.exe"
# Variables
# $startup = "C:\Users\Kenneth\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
# $ytdls = "f:/ytdls"
$scripts = "c:/shellpower"
# $mdn = "E:\gitting\gitclone\clones\mdn\content\files\en-us"
# $samples = join-path $ytdls "samples"
# $filth = "e:/projects/web/tilde/eli2and40-tilde_club/organized"
$EDITOR=(where.exe hx)
if ($PWD -eq "C:\Windows\System32") {
cd ~
}
# clear
3 changes: 2 additions & 1 deletion alert.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
$n = if ($args.length) {$args[0] - 1} else {get-random 12}
$n = if ($args.length) {$args[0] - 1} else {(get-random 12)+1}
echo $n
foreach ($i in (0..$n)) {play (get-random)}
3 changes: 3 additions & 0 deletions basename.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foreach ($arg in $args) {
split-path -Path $arg -Leaf
}
6 changes: 6 additions & 0 deletions beep.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
param(
[double]$freq = 440,
[double]$len = 300
)

[console]::beep($freq, $len)
32 changes: 32 additions & 0 deletions deploy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function goBack {
if ($startingDir) {
cd $startingDir
}
}

if ((split-path -Path $pwd -Leaf).ToLower() -ne "shellpower") {
if ($scripts) {
$startingDir=$pwd
cd $scripts
} else {
echo "not in shellpower and cannot find it"
exit 1
}
}

if ($profile) {
if (test-path -Path $profile) {
echo '$profile already exists, not sure what to do (replace or add a source/.).'
goBack
exit 1
}
if (!(test-path -Path .profile)) {
echo 'cannot find .profile to source to $profile'
goBack
exit 1
}
# cat .profile > $profile
New-Item -ItemType HardLink -Path "$profile" -Target "$(join-path $pwd .profile)" > $null && echo 'hard linked $profile'
}

goBack
6 changes: 0 additions & 6 deletions isfile.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
foreach ($arg in $args) {
# $isfile = Test-Path -Path $arg -PathType Leaf
Test-Path -Path $arg -PathType Leaf
# echo $isfile
# yield $isfile
}


# rfile
36 changes: 36 additions & 0 deletions ls.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# function ls {
# if ($args.length -gt 1) {
# if (isdir $args[0]) {
# for ($i=1; $i -lt $args.length; $i++) {
# get-childitem -name $args[0] $args[$i]
# }
# } else{
# foreach ($arg in $args) {
# get-childitem -name $arg
# }
# }
# } else {
# get-childitem -name $args[0]
# }
# }

# ls $args

function ls {
if ($args.length -gt 1) {
if (isdir $args[0]) {
for ($i=1; $i -lt $args.length; $i++) {
get-childitem -name $args[0] $args[$i]
}
} else{
foreach ($arg in $args) {
get-childitem -name $arg
}
}
} else {
get-childitem -name $args[0]
}
}

ls $args
42 changes: 42 additions & 0 deletions mkimagelist.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
param (
[string[]]$Paths
)

# Define a list of image file extensions to check for (in lowercase)
$imageExtensions = @("jpg", "jpeg", "png", "gif", "bmp", "tiff")

# Initialize an array to hold image paths
$imageList = @()

# Iterate through each path provided as an argument
foreach ($path in $Paths) {
# Check if the path is a directory
if (Test-Path $path -PathType Container) {
# Get all files in the directory and check their extensions
$files = Get-ChildItem -Path $path -File -Recurse
foreach ($file in $files) {
# Get the file extension and convert it to lowercase
$extension = $file.Extension.TrimStart('.').ToLower()
if ($imageExtensions -contains $extension) {
$imageList += (Resolve-Path $file.FullName)
}
}
}
# Check if the path is a file and an image
elseif (Test-Path $path -PathType Leaf) {
# Get the file extension and convert it to lowercase
$extension = $path.Substring($path.LastIndexOf('.') + 1).ToLower()
if ($imageExtensions -contains $extension) {
$imageList += (Resolve-Path $path)
}
}
}

# Create the image_list.txt file in the current working directory
$imageListPath = Join-Path -Path (Get-Location) -ChildPath "image_list.txt"

# Write the image paths to the file
$imageList | ForEach-Object { "file '$($_)'" } | Set-Content -Path $imageListPath -Encoding UTF8

# Inform the user about the created file
Write-Host "Image list created at: $imageListPath"
1 change: 1 addition & 0 deletions mkimagevid.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ffmpeg -r 0.1 -f concat -safe 0 -i image_list.txt -c:v libx264 -pix_fmt yuv420p out.mp4
8 changes: 8 additions & 0 deletions mkvid.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
image = $args[0]
audio = $args[1]
ffmpeg -loop 1 -i $image -i $audio -c:v libx264 -tune stillimage -c:a copy -b:a 192k -pix_fmt yuv420p -shortest out.mp4

# https://duckduckgo.com/?q=ffmpeg+combine+photo+and+audio&t=ffab&ia=web&iax=qa | ffmpeg combine photo and audio at DuckDuckGo
# https://www.bannerbear.com/blog/how-to-create-a-slideshow-from-images-with-ffmpeg/ | How to Create a Slideshow from Images with FFmpeg - Bannerbear
# https://ffmpeg.org/ffmpeg.html | ffmpeg Documentation
# https://duckduckgo.com/?t=ffab&q=high+level+mp4+library&ia=web | high level mp4 library at DuckDuckGo
21 changes: 17 additions & 4 deletions new.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,30 @@ $help = 'Create new powershell scripts
$scripts/name2.ps1
...
$scripts/nameN.ps1
And then open each file with the system default
And then open each file with the "editor" command defined in $profile
'



$pths=@((join-path $scripts "readme.md"))

if ($args.length) {
foreach ($arg in $args) {
$pth = join-path $scripts $arg
$pth += ($pth.endswith(".ps1")) ? "" : ".ps1"
touch $pth
editor (join-path $scripts "readme.md")
editor $pth
$pths += $pth
}
} else {
echo $help
}

# echo $pths

editor ($pths)

# clean up
foreach ($file in (dir $scripts)) {
if (!$file.length) {
rm $file
}
}
1 change: 1 addition & 0 deletions open.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoke-item $args[0]
18 changes: 6 additions & 12 deletions play.ps1
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
# $root = 440
# $octave = 5
# $length = 300 # milisecs
$root = 440
$octave = 5
$length = 300 # milisecs

param(
[double]$root = 440,
[double]$octave = 11,
[double]$length = 300
)
foreach ($i in $args) {
# if (($i -is [int32]) -or ($i -is [int64]) -or ($i -is [double])) {
if (($i -is [int32]) -or ($i -is [int64]) -or ($i -is [double])) {
# $freq = $root + (($root / $octave) * ($i % $octave))
$freq = $root / $octave
$freq
# $freq
$freq *= $i % $octave
$freq
# $freq
$freq += $root
$freq
# $freq
[console]::beep($freq, $length)
} elseif ($i -is [array]) {
foreach ($j in $i) {
Expand All @@ -25,4 +20,3 @@ foreach ($i in $args) {
}
}
}
$args
40 changes: 39 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A collection of powershell scripts to help aid and play flows
[_**how**_](#usage)

_**why**_
*Stubby little fingers grow weary of tired analogies*
*Stubby little fingers grow weary of repeaded command sequences*

### Usage
This repository holds PowerShell scripts that I created for personal convenience.
Expand All @@ -25,6 +25,7 @@ You *__will__* have to personalize:
- [new](#new)
- [profile](#profile)
- [ytdls](#ytdls)

- [gitfast](#gitfast)

You *__may__* have to personalize:
Expand Down Expand Up @@ -55,6 +56,13 @@ Echo a line of text comprised by a repetition of your chosen string
qwertyqwertyqwerty
```

##### basename
offers the same functionality as the eponymous bash command
```powershell
> (basename "c:/program files") -eq "program files"
True
```

##### blank
Echo n blank lines
```powershell
Expand Down Expand Up @@ -127,6 +135,12 @@ Copy the name of a random item in the current directory to the clipboard
```
- *See Also:* [names](#names)

##### deploy
a set up script for installing the `.profile`
```powershell
> deploy
```

##### dls
Clears the screen before implementing [cdls](#cdls)
```powershell
Expand Down Expand Up @@ -325,6 +339,24 @@ Opens the mozilla mdn docs in explorer
- assumes you've set a `$mdn` variable


##### mkimagelist
takes file and directory paths and creates a file, named `image_list.txt` with the found images for giving to `ffmpeg`
```powershell
> mkimagelist [path1 [path2 ...]]
```

##### mkimagevid
Commands ffmpeg to create a video using the file generated by `mkimagelist`. The resulting file will be called `out.mp4`
```powershell
> mkimagevid
```

##### mkvid
Commands `ffmpeg` to create a video using a given image and audio file. The resulting file will be called `out.mp4`
```powershell
> mkvid image/file/path audio/file/path
```

##### names
run `ls -n` aka `get-childitem -n` and filter for files whose names match arguments
```powershell
Expand Down Expand Up @@ -388,6 +420,12 @@ Find out precisely where executables on the path are located
- *Note:* You will have to append '.ps1' if you are looking for powershell scripts


##### open
Open the given file with the default program
```powershell
> open path/to/file
```

##### pcd
cd into the directory in your clipboard
```powershell
Expand Down
3 changes: 2 additions & 1 deletion y22.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ for ($i=0; $i -lt $args.length; $i++) {
cd $ytdls
blank ($i -eq 0 ? 0: 3)
ind ($i+1) $args.length
youtube-dl -f 22 $args[$i]
# youtube-dl -f 22 $args[$i]
yt-dlp -f 22 $args[$i]
cd $origin
}
2 changes: 1 addition & 1 deletion yda.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ foreach ($arg in $args) {
$n += 1
cd $destination
ind $n $args.length
youtube-dl -x $arg
yt-dlp -x $arg
cd $origin
''
''
Expand Down
3 changes: 2 additions & 1 deletion ydl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ foreach ($link in $args) {
$n += 1
cd $destination
ind $n $args.length
youtube-dl $link
# youtube-dl $link
yt-dlp $link
cd $origin
''
''
Expand Down

0 comments on commit a6d2e60

Please sign in to comment.