NAME

cdprevsibling-backend - Change to the "previous" or "next" sibling directory

VERSION

This document describes version 0.012 of cdprevsibling-backend (from Perl distribution App-CdUtils), released on 2025-11-04.

SYNOPSIS

To use in shell:

% cdprevsibling() { cd `cdprevsibling-backend "$1"`; }
% cdnextsibling() { cd `cdnextsibling-backend "$1"`; }

% pwd
/some/path

% ls
four/   one/   three/   two/

% cd four

% cdnextsibling
% pwd
/some/path/one

% cdnextsibling -n2
% pwd
/some/path/two

% cdprevsibling -n3
% pwd
/some/path/four

# when there is no previous/next sibling, will stay at the current position
% cdprevsibling
% pwd
/some/path/four

DESCRIPTION

cdprevsibling and cdnextsibling are commands to change to "previous" and "next" sibling directories, respectively. By default, asciibetical ordering is used. You can change the ordering by setting the "CDPREVNEXTSIBLING_SORT_FILES_OPTS" options, as sort-files utility is used to sort the directories.

OPTIONS

--num=i, -n

Integer. Default 1. Sibling distance to go to. 1 means the closest, i.e. if current position is at number 5, the previous sibling is 4 and next sibling is 6. If this option is 2, it means the second closest, i.e. if current position is at number 5, previous sibling is 3 and next sibling is 7. And so on.

--level=i, -l

Integer. Default is 1. Number of level to go upwards to find siblings for. For example:

A/
  X0/
  X1/
    Y/
  X2/
B/
  X0/
  X1/
    Z/
  X2/

If current position is /A/X1 and level is 1, previous sibling would be /A/X0 and next sibling would be /A/X2.

If current position is /A/X1 and level is 2, next sibling would be /B/X1 because we are finding sibling for A, not X1.

When level is larger than 1, it is possible that the sibling do not have the same structure. In that case, this script will stop at the last depth where the same directory can be found. For example, if current position is /A/X1/Y and level is 3, next sibling should be /B/X1/Y. However, since the path does not exist, the script will return /B/X1.

COMPLETION

This script has shell tab completion capability with support for several shells.

bash

To activate bash completion for this script, put:

complete -C cdprevsibling-backend cdprevsibling-backend

in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.

It is recommended, however, that you install modules using cpanm-shcompgen which can activate shell completion for scripts immediately.

tcsh

To activate tcsh completion for this script, put:

complete cdprevsibling-backend 'p/*/`cdprevsibling-backend`/'

in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.

It is also recommended to install shcompgen (see above).

other shells

For fish and zsh, install shcompgen as described above.

ENVIRONMENT

CDPREVNEXTSIBLING_SORT_FILES_OPTS

String. Options to pass to sort-files. Default: --by-field name.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/App-CdUtils.

SOURCE

Source repository is at https://github.com/perlancar/perl-App-CdUtils.

SEE ALSO

AUTHOR

perlancar <perlancar@cpan.org>

CONTRIBUTING

To contribute, you can send patches by email/via RT, or send pull requests on GitHub.

Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:

% prove -l

If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.

COPYRIGHT AND LICENSE

This software is copyright (c) 2025 by perlancar <perlancar@cpan.org>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-CdUtils

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.