App-nup

 view release on metacpan or  search on metacpan

script/nup  view on Meta::CPAN

        echo "${alias[$cmd_name]}"
    else
        echo "$1"
    fi
}

# Check if any file matches comma-separated extension list
# Usage: match_ext "pdf,docx,xlsx" file1.pdf file2.txt
match_ext() {
    local ext_list="$1"; shift
    local ext
    for f in "$@"; do
        ext="${f##*.}"
        ext="${ext,,}"  # lowercase
        [[ ",$ext_list," == *,"$ext",* ]] && return 0
    done
    return 1
}

# Additional optex modules
declare -a optex_mod=()
if [[ -n $textconv && $textconv != none ]] && match_ext "$textconv" "$@"; then
    optex_mod+=(-Mtextconv)
fi

if is_command_mode "$@"; then
    # Command mode: use optex -Mup
    [[ ${parallel:-} ]] && paginate=
    local_cmd="$1"; shift
    declare -a expanded_cmd
    read -ra expanded_cmd <<< "$(expand_alias "$local_cmd")"
    declare -a target=("${expanded_cmd[@]}" "$@")
else
    # File view mode: use ansicolumn via optex -Mup
    [[ ${parallel:-} ]] || (( $# > 1 )) && paginate=
    declare -a target=(ansicolumn "$@")
fi

# Disable page mode for --no-paginate/-F, or for parallel layout
# (-V or multiple files) which has no page structure
[[ -z ${paginate:-} ]] && up_opts+=(--no-paginate)

declare -a cmd=(optex "${optex_mod[@]}" -Mup "${up_opts[@]}" -- "${target[@]}")

debug "command: ${cmd[*]}"

[[ ${dryrun:-} ]] && { echo "${cmd[@]}"; exit; }

exec "${cmd[@]}"

: <<'=cut'

=head1 DESCRIPTION

B<N-up> (command: C<nup>) is a multi-column paged output tool.
It provides a convenient way to view files or run commands in
n-up layout using the L<App::optex::up> module through C<optex>.

=begin html

<p><img width="750" src="https://raw.githubusercontent.com/tecolicom/App-nup/main/images/nup.png"></p>

=end html

C<nup> automatically detects the mode based on the first argument:
if it is an existing file, n-up file view mode is used; if it is an
executable command, n-up command mode is used.  Use C<-e> option to
force command mode when needed.

=head1 OPTIONS

=head2 General Options

=over 4

=item B<-h>, B<--help>

Show help message.

=item B<--version>

Show version.

=item B<-d>, B<--debug>

Enable debug mode.

=item B<-n>, B<--dryrun>

Dry-run mode. Show the command without executing.

=item B<-e>, B<--exec>

Force command execution mode. Normally the mode is auto-detected,
but use this option when you want to execute a file as a command.

=item B<--alias>=I<NAME>=I<CMD> I<OPTS>...

Define command alias. When a command matches I<NAME>, it is replaced
by I<CMD> with specified I<OPTS>.  This can be used to add default
options or to substitute a different command.
Multiple C<--alias> options can be specified.

Default aliases:

    bat     bat --style=plain --color=always
    batcat  batcat --style=plain --color=always
    rg      rg --color=always
    tree    tree -C

Example:

    nup --alias='grep=ggrep --color=always' grep pattern file

=item B<-V>, B<--parallel>

Enable parallel view mode for ansicolumn.  In this mode, each file
is displayed in its own column without pagination, similar to
C<--no-paginate>.  Automatically enabled when multiple files are
specified.  Single file or stdin input results in single column
output.



( run in 0.660 second using v1.01-cache-2.11-cpan-788537b7465 )