Remove 'query: ' prefix from 'zoxide query'

This commit is contained in:
Ajeet D'Souza 2020-04-03 02:22:50 +05:30
parent fdf46d34b9
commit d3e49bde66
2 changed files with 23 additions and 32 deletions

View File

@ -142,61 +142,53 @@ z() {
if [ -n "$OLDPWD" ]; then if [ -n "$OLDPWD" ]; then
_z_cd "$OLDPWD" || return "$?" _z_cd "$OLDPWD" || return "$?"
else else
echo "zoxide: \$OLDPWD is not set" echo 'zoxide: $OLDPWD is not set'
return 1 return 1
fi fi
else else
result="$(zoxide query "$@")" || return "$?" result="$(zoxide query "$@")" || return "$?"
case "$result" in if [ -d "$result" ]; then
"query: "*) _z_cd "$result" || return "$?"
_z_cd "${result#query: }" || return "$?" elif [ -n "$result" ]; then
;;
*)
if [ -n "$result" ]; then
echo "$result" echo "$result"
fi fi
;;
esac
fi fi
} }
"#; "#;
const FISH_Z: &str = r#" const FISH_Z: &str = r#"
function _z_cd function _z_cd
cd "$argv" cd $argv
or return "$status" or return $status
commandline -f repaint commandline -f repaint
if [ -n "$_ZO_ECHO" ] if test -n "$_ZO_ECHO"
echo "$PWD" echo $PWD
end end
end end
function z function z
set argc (count "$argv") set argc (count $argv)
if [ "$argc" -eq 0 ] if test $argc -eq 0
_z_cd "$HOME" _z_cd $HOME
or return "$status" or return $status
else if [ "$argc" -eq 1 ]; and [ "$argv[1]" = '-' ] else if test $argc -eq 1 -a $argv[1] = '-'
_z_cd '-' _z_cd -
or return "$status" or return $status
else else
# TODO: use string-collect from fish 3.1.0 once it has wider adoption # FIXME: use string-collect from fish 3.1.0 once it has wider adoption
set -l IFS '' set -l IFS ''
set -l result (zoxide query $argv) set -l result (zoxide query $argv)
switch "$result" if test -d $result
case 'query: *' _z_cd $result
_z_cd (string sub -s 8 "$result") or return $status
or return "$status" else if test -n "$result"
case '*' echo $result
if [ -n "$result" ]
echo "$result"
end
end end
end end
end end

View File

@ -26,7 +26,6 @@ impl Query {
Some(path) => { Some(path) => {
let stdout = io::stdout(); let stdout = io::stdout();
let mut handle = stdout.lock(); let mut handle = stdout.lock();
handle.write_all(b"query: ").unwrap();
handle.write_all(&path).unwrap(); handle.write_all(&path).unwrap();
handle.write_all(b"\n").unwrap(); handle.write_all(b"\n").unwrap();
} }