mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-18 08:51:15 -03:00
The overwhelming majority of localizable messages comes from
completions:
$ ls share/completions/ | wc -l
$ 1048
OTOH functions also contribute a small amount, mostly via their
descriptions (so usually just one per file).
$ ls share/functions/ | wc -l
$ 237
Most of these are private and almost never shown to the user, so it's
not worth bothering translators with them. So:
- Skip private (see the parent commit) and deprecated functions.
- Skip wrapper functions like grep (where the translation seems to
be provided by apropos), and even the English description is not
helpful.
- Assume that most real systems have "seq", "realpath" etc.,
so it's no use providing our own translations for our fallbacks.
- Mark fish's own functions as tier1, and some barely-used functiosn
and completions as tier3, so we can order them that way in
po/*.po. Most translators should only look at tier1 and tier2.
In future we could disable localization for tier3.
See the explanation at the bottom of
tests/checks/message-localization-tier-is-declared.fish
Part of #11833
83 lines
2.3 KiB
Fish
83 lines
2.3 KiB
Fish
# localization: tier1
|
|
function pushd --description 'Push directory to stack'
|
|
set -l rot_r
|
|
set -l rot_l
|
|
|
|
if count $argv >/dev/null
|
|
# check for --help
|
|
switch $argv[1]
|
|
case -h --h --he --hel --help
|
|
__fish_print_help pushd
|
|
return 0
|
|
end
|
|
|
|
# emulate bash by checking if argument of form +n or -n
|
|
if string match -qr '^-[0-9]+$' -- $argv[1]
|
|
set rot_r (string sub -s 2 -- $argv[1])
|
|
else if string match -qr '^\+[0-9]+$' -- $argv[1]
|
|
set rot_l (string sub -s 2 -- $argv[1])
|
|
end
|
|
end
|
|
|
|
set -q dirstack
|
|
or set -g dirstack
|
|
|
|
# emulate bash: an empty pushd should switch the top of dirs
|
|
if not set -q argv[1]
|
|
# check that the stack isn't empty
|
|
if not set -q dirstack[1]
|
|
echo "pushd: no other directory" >&2
|
|
return 1
|
|
end
|
|
|
|
# get the top two values of the dirs stack ... the first is pwd
|
|
set -l top_dir $PWD
|
|
set -l next_dir $dirstack[1]
|
|
|
|
# alter the top of dirstack and move to directory
|
|
set -g dirstack[1] $top_dir
|
|
cd $next_dir
|
|
return
|
|
end
|
|
|
|
# emulate bash: check for rotations
|
|
if test -n "$rot_l" -o -n "$rot_r"
|
|
# grab the current stack
|
|
set -l stack $PWD $dirstack
|
|
|
|
# translate a right rotation to a left rotation
|
|
if test -n "$rot_r"
|
|
# check the rotation in range
|
|
if test $rot_r -ge (count $stack)
|
|
echo "pushd: -$rot_r: directory stack index out of range" >&2
|
|
return 1
|
|
end
|
|
|
|
set rot_l (math (count $stack) - 1 - $rot_r)
|
|
end
|
|
|
|
# check the rotation in range
|
|
if test $rot_l -ge (count $stack)
|
|
echo "pushd: +$rot_l: directory stack index out of range" >&2
|
|
return 1
|
|
else
|
|
# rotate stack unless rot_l is 0
|
|
if test $rot_l -gt 0
|
|
set stack $stack[(math $rot_l + 1)..(count $stack)] $stack[1..$rot_l]
|
|
end
|
|
|
|
# now reconstruct dirstack and change directory
|
|
set -g dirstack $stack[2..(count $stack)]
|
|
cd $stack[1]
|
|
end
|
|
|
|
# print the new stack
|
|
dirs
|
|
return
|
|
end
|
|
|
|
# argv[1] is a directory
|
|
set -l old_pwd $PWD
|
|
cd $argv[1]; and set -g -p dirstack $old_pwd
|
|
end
|