Skip to content

Commit

Permalink
add -dir param to powershell script
Browse files Browse the repository at this point in the history
  • Loading branch information
hamvocke committed Jan 8, 2024
1 parent f0cf27f commit c598ba2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ New-Alias lnks "$Home\your-lnks-dir\lnks.ps1"
```
Usage: lnks.sh [OPTIONS...]
-k --keep-open Keep lnks open after selecting a bookmark
-d <dir> --dir <dir> Specify a directory bookmarks are stored (*nix only)
-d <dir> --dir <dir> Specify a directory where bookmarks files are stored
```

## Working with a team
Expand Down
10 changes: 6 additions & 4 deletions lnks.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env pwsh

param (
[switch][Alias("k", "keep-open")] $keepOpen = $false
[switch][Alias("k", "keep-open")] $keepOpen = $false,
[Alias("d", "dir")] $lnksDirectory
)

try
Expand All @@ -26,12 +27,13 @@ else
$enterCommand += "+abort"
}

$lnksDirectory = Split-Path -Path $PSCommandPath -Parent
if ($lnksDirectory -eq $null) {
$lnksDirectory = Split-Path -Path $PSCommandPath -Parent
}

Get-Content "$lnksDirectory\*.txt" | fzf `
--border=rounded --margin=5% `
--border=rounded `
--prompt="Search Bookmarks > " `
--with-nth='1..-2' `
--bind=$enterCommand `
--preview='echo {-1}' --preview-window='up,1'

22 changes: 11 additions & 11 deletions lnks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ keep_open=false
dir="$(dirname "$0")"

usage () {
echo "Usage: $(basename "$0") [OPTIONS...]"
echo " -k --keep-open Keep lnks open after selecting a bookmark"
echo " -d <dir> --dir <dir> Specify a directory bookmarks are stored"
exit 0
echo "Usage: $(basename "$0") [OPTIONS...]"
echo " -k --keep-open Keep lnks open after selecting a bookmark"
echo " -d <dir> --dir <dir> Specify a directory where bookmarks files are stored"
exit 0
}

while [[ "$#" -gt 0 ]]; do
case $1 in
-k|--keep-open) keep_open=true ;;
-d|--dir) dir="$2"; shift ;; # TODO: validation
-d|--dir) dir="$2"; shift ;;
-h|--help) usage ;;
*) echo "Unknown parameter passed: $1" >&2; exit 1 ;;
esac
Expand All @@ -46,9 +46,9 @@ else
fi

cat "$dir"/*.txt | fzf \
--border=rounded \
--prompt="Search Bookmarks > " \
--with-nth='1..-2' \
--bind="${enter_command}" \
--preview='echo {-1}' \
--preview-window='up,1'
--border=rounded \
--prompt="Search Bookmarks > " \
--with-nth='1..-2' \
--bind="${enter_command}" \
--preview='echo {-1}' \
--preview-window='up,1'

0 comments on commit c598ba2

Please sign in to comment.