Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions Completions/wayshot.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
_wayshot() {
local i cur prev opts cmd
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cmd=""
opts=""

for i in ${COMP_WORDS[@]}
do
case "${cmd},${i}" in
",$1")
cmd="wayshot"
;;
*)
;;
esac
done

case "${cmd}" in
wayshot)
opts="-s -c -l -o -h -V --clipboard --log-level --slurp --cursor --extension --format --output-format --encoding --list-outputs --output --choose-output --generate-completions --help --version [OUTPUT]"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
--log-level)
COMPREPLY=($(compgen -W "trace debug info warn error" -- "${cur}"))
return 0
;;
--slurp)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-s)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--encoding)
COMPREPLY=($(compgen -W "jpg png ppm qoi webp" -- "${cur}"))
return 0
;;
--extension)
COMPREPLY=($(compgen -W "jpg png ppm qoi webp" -- "${cur}"))
return 0
;;
--format)
COMPREPLY=($(compgen -W "jpg png ppm qoi webp" -- "${cur}"))
return 0
;;
--output-format)
COMPREPLY=($(compgen -W "jpg png ppm qoi webp" -- "${cur}"))
return 0
;;
--output)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-o)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--generate-completions)
COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}"))
return 0
;;
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
esac
}

if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
complete -F _wayshot -o nosort -o bashdefault -o default wayshot
else
complete -F _wayshot -o bashdefault -o default wayshot
fi
44 changes: 44 additions & 0 deletions Completions/wayshot.elvish
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

use builtin;
use str;

set edit:completion:arg-completer[wayshot] = {|@words|
fn spaces {|n|
builtin:repeat $n ' ' | str:join ''
}
fn cand {|text desc|
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
}
var command = 'wayshot'
for word $words[1..-1] {
if (str:has-prefix $word '-') {
break
}
set command = $command';'$word
}
var completions = [
&'wayshot'= {
cand --log-level 'Log level to be used for printing to stderr'
cand -s 'Arguments to call slurp with for selecting a region'
cand --slurp 'Arguments to call slurp with for selecting a region'
cand --encoding 'Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.'
cand --extension 'Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.'
cand --format 'Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.'
cand --output-format 'Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.'
cand -o 'Choose a particular output/display to screenshot'
cand --output 'Choose a particular output/display to screenshot'
cand --generate-completions 'This Command helps you generate autocomplete in your desired Shell environment'
cand --clipboard 'Copy image to clipboard. Can be used simultaneously with [OUTPUT] or stdout. Wayshot persists in the background offering the image till the clipboard is overwritten.'
cand -c 'Enable cursor in screenshots'
cand --cursor 'Enable cursor in screenshots'
cand -l 'List all valid outputs'
cand --list-outputs 'List all valid outputs'
cand --choose-output 'Present a fuzzy selector for output/display selection'
cand -h 'Print help (see more with ''--help'')'
cand --help 'Print help (see more with ''--help'')'
cand -V 'Print version'
cand --version 'Print version'
}
]
$completions[$command]
}
11 changes: 11 additions & 0 deletions Completions/wayshot.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
complete -c wayshot -l log-level -d 'Log level to be used for printing to stderr' -r -f -a "{trace '',debug '',info '',warn '',error ''}"
complete -c wayshot -s s -l slurp -d 'Arguments to call slurp with for selecting a region' -r
complete -c wayshot -l encoding -l extension -l format -l output-format -d 'Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.' -r -f -a "{jpg 'JPG/JPEG encoder',png 'PNG encoder',ppm 'PPM encoder',qoi 'Qut encoder',webp 'WebP encoder,'}"
complete -c wayshot -s o -l output -d 'Choose a particular output/display to screenshot' -r
complete -c wayshot -l generate-completions -d 'This Command helps you generate autocomplete in your desired Shell environment' -r -f -a "{bash '',elvish '',fish '',powershell '',zsh ''}"
complete -c wayshot -l clipboard -d 'Copy image to clipboard. Can be used simultaneously with [OUTPUT] or stdout. Wayshot persists in the background offering the image till the clipboard is overwritten.'
complete -c wayshot -s c -l cursor -d 'Enable cursor in screenshots'
complete -c wayshot -s l -l list-outputs -d 'List all valid outputs'
complete -c wayshot -l choose-output -d 'Present a fuzzy selector for output/display selection'
complete -c wayshot -s h -l help -d 'Print help (see more with \'--help\')'
complete -c wayshot -s V -l version -d 'Print version'
50 changes: 50 additions & 0 deletions Completions/wayshot.powershell
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

using namespace System.Management.Automation
using namespace System.Management.Automation.Language

Register-ArgumentCompleter -Native -CommandName 'wayshot' -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)

$commandElements = $commandAst.CommandElements
$command = @(
'wayshot'
for ($i = 1; $i -lt $commandElements.Count; $i++) {
$element = $commandElements[$i]
if ($element -isnot [StringConstantExpressionAst] -or
$element.StringConstantType -ne [StringConstantType]::BareWord -or
$element.Value.StartsWith('-') -or
$element.Value -eq $wordToComplete) {
break
}
$element.Value
}) -join ';'

$completions = @(switch ($command) {
'wayshot' {
[CompletionResult]::new('--log-level', 'log-level', [CompletionResultType]::ParameterName, 'Log level to be used for printing to stderr')
[CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'Arguments to call slurp with for selecting a region')
[CompletionResult]::new('--slurp', 'slurp', [CompletionResultType]::ParameterName, 'Arguments to call slurp with for selecting a region')
[CompletionResult]::new('--encoding', 'encoding', [CompletionResultType]::ParameterName, 'Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.')
[CompletionResult]::new('--extension', 'extension', [CompletionResultType]::ParameterName, 'Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.')
[CompletionResult]::new('--format', 'format', [CompletionResultType]::ParameterName, 'Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.')
[CompletionResult]::new('--output-format', 'output-format', [CompletionResultType]::ParameterName, 'Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.')
[CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Choose a particular output/display to screenshot')
[CompletionResult]::new('--output', 'output', [CompletionResultType]::ParameterName, 'Choose a particular output/display to screenshot')
[CompletionResult]::new('--generate-completions', 'generate-completions', [CompletionResultType]::ParameterName, 'This Command helps you generate autocomplete in your desired Shell environment')
[CompletionResult]::new('--clipboard', 'clipboard', [CompletionResultType]::ParameterName, 'Copy image to clipboard. Can be used simultaneously with [OUTPUT] or stdout. Wayshot persists in the background offering the image till the clipboard is overwritten.')
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Enable cursor in screenshots')
[CompletionResult]::new('--cursor', 'cursor', [CompletionResultType]::ParameterName, 'Enable cursor in screenshots')
[CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'List all valid outputs')
[CompletionResult]::new('--list-outputs', 'list-outputs', [CompletionResultType]::ParameterName, 'List all valid outputs')
[CompletionResult]::new('--choose-output', 'choose-output', [CompletionResultType]::ParameterName, 'Present a fuzzy selector for output/display selection')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
})

$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
Sort-Object -Property ListItemText
}
71 changes: 71 additions & 0 deletions Completions/wayshot.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#compdef wayshot

autoload -U is-at-least

_wayshot() {
typeset -A opt_args
typeset -a _arguments_options
local ret=1

if is-at-least 5.2; then
_arguments_options=(-s -S -C)
else
_arguments_options=(-s -C)
fi

local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" \
'--log-level=[Log level to be used for printing to stderr]:LOG_LEVEL:(trace debug info warn error)' \
'-s+[Arguments to call slurp with for selecting a region]' \
'--slurp=[Arguments to call slurp with for selecting a region]' \
'--encoding=[Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.]:FILE_EXTENSION:((jpg\:"JPG/JPEG encoder"
png\:"PNG encoder"
ppm\:"PPM encoder"
qoi\:"Qut encoder"
webp\:"WebP encoder,"))' \
'--extension=[Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.]:FILE_EXTENSION:((jpg\:"JPG/JPEG encoder"
png\:"PNG encoder"
ppm\:"PPM encoder"
qoi\:"Qut encoder"
webp\:"WebP encoder,"))' \
'--format=[Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.]:FILE_EXTENSION:((jpg\:"JPG/JPEG encoder"
png\:"PNG encoder"
ppm\:"PPM encoder"
qoi\:"Qut encoder"
webp\:"WebP encoder,"))' \
'--output-format=[Set image encoder, by default uses the file extension from the OUTPUT positional argument. Otherwise defaults to png.]:FILE_EXTENSION:((jpg\:"JPG/JPEG encoder"
png\:"PNG encoder"
ppm\:"PPM encoder"
qoi\:"Qut encoder"
webp\:"WebP encoder,"))' \
'(-s --slurp)-o+[Choose a particular output/display to screenshot]:OUTPUT: ' \
'(-s --slurp)--output=[Choose a particular output/display to screenshot]:OUTPUT: ' \
'--generate-completions=[This Command helps you generate autocomplete in your desired Shell environment]:GENERATE_COMPLETIONS:(bash elvish fish powershell zsh)' \
'--clipboard[Copy image to clipboard. Can be used simultaneously with \[OUTPUT\] or stdout. Wayshot persists in the background offering the image till the clipboard is overwritten.]' \
'-c[Enable cursor in screenshots]' \
'--cursor[Enable cursor in screenshots]' \
'-l[List all valid outputs]' \
'--list-outputs[List all valid outputs]' \
'(-s --slurp -o --output)--choose-output[Present a fuzzy selector for output/display selection]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
'::file -- Custom output path can be of the following types\:
1. Directory (Default naming scheme is used for the image output).
2. Path (Encoding is automatically inferred from the extension).
3. `-` (Indicates writing to terminal \[stdout\]).:_files' \
&& ret=0
}

(( $+functions[_wayshot_commands] )) ||
_wayshot_commands() {
local commands; commands=()
_describe -t commands 'wayshot commands' commands "$@"
}

if [ "$funcstack[1]" = "_wayshot" ]; then
_wayshot "$@"
else
compdef _wayshot wayshot
fi
2 changes: 1 addition & 1 deletion wayshot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ repository.workspace = true
flate2 = "1.0.35"
eyre = "0.6.12"


[dependencies]
tracing.workspace = true

libwayshot.workspace = true

clap = { version = "4.5.32", features = ["derive"] }
clap_complete = "4.5.46"
tracing-subscriber = "0.3.19"

image = { version = "0.25", default-features = false, features = [
Expand Down
9 changes: 9 additions & 0 deletions wayshot/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use clap::{
use tracing::Level;

use crate::utils::EncodingFormat;
use clap_complete::Shell;

fn get_styles() -> Styles {
Styles::styled()
Expand Down Expand Up @@ -75,4 +76,12 @@ pub struct Cli {
/// 3. `None` -- if the config isn't found, the `Config::default()` will be used
#[arg(long, verbatim_doc_comment)]
pub config: Option<PathBuf>,

///Generate shell completions for the specified shell (Example: bash, zsh, fish)
#[arg(
long,
value_enum,
help = "This Command helps you generate autocomplete in your desired Shell environment"
)]
pub generate_completions: Option<Shell>,
}
Loading
Loading