jorgebucaran / replay.fish Goto Github PK
View Code? Open in Web Editor NEWRun Bash commands, replay changes in Fish π€
License: MIT License
Run Bash commands, replay changes in Fish π€
License: MIT License
$ time fish -c "replay export foo=1"
0.01 real 0.01 user 0.00 sys
$ time fish -c "bass export foo=1"
0.14 real 0.05 user 0.07 sys
$ time fish -c 'replay "source ~/.nvm/nvm.sh --no-use; nvm use v11.10.0"'
Now using node v11.10.0 (npm v6.7.0)
0.70 real 0.52 user 0.18 sys
$ time fish -c 'bass "source ~/.nvm/nvm.sh --no-use; nvm use v11.10.0"'
Now using node v11.10.0 (npm v6.7.0)
0.83 real 0.58 user 0.26 sys
cd 'System Volume Information'
works, but
replay cd 'System Volume Information'
don't work, neither
replay cd System\ Volume\ Information/
erro: bash: line 2: cd: too many arguments
I'm unable to run this command. I'd like to use replay to run bash commands that use $
and it's unsupported by fish.
β― replay "export TEST=$(pwd)"
fish: $(...) is not supported. In fish, please use '(pwd)'.
replay "export TEST=$(pwd)"
Hi! First of all, I would like to thank you for this nice tool. I ran into an issue today when using it in a nix shell. This shell sets a variable $shellHook
which has quotes (specifically "
) in it, which results in replay
printing some part of the value of $shellHook
.
I didn't manage to reproduce the printing, but there is definitely something wrong with quotes handling:
$ replay 'export TEST=\'echo "hi"\''
$ echo $TEST
echo hi
Quotes around hi
are missing. I played around a little myself and this seems to fix the issue:
36c36,37
< echo "set --global --export $name \"$value\""
---
> set --local tmp (string replace --all \" \\\" $value)
> echo "set --global --export $name \"$tmp\""
I would make a PR, but I don't know enough about how replay
works to know if there are problems with this or other changes are needed.
Given a file hook.sh
:
export shellHook='"${DIRENV_IN_ENVRC}"
'
Then, replay . hook.sh
errors:
$ replay . hook.sh
- (line 1): Expected a variable name after this $.
set --global --export shellHook \"\\$\{DIRENV_IN_ENVRC\}\"\
^
from sourcing file -
called on line 25 of file ~/.config/fish/fundle/jorgebucaran/replay.fish/functions/replay.fish
in function 'replay' with arguments '. hook.sh'
source: Error while reading file '<stdin>'
I'm not sure what exactly causes this bug, but it seems to be the combination of a multiline variable and the braced ${VARIABLE}
notation.
I assume part of this bug is from the complexity of escaping in replay.fish
: first the variable contents are passed to string escape
, then piped through string replace --all -- \$ \\\$
, then through string replace --all -- \\n \n
.
After inserting some debugging statements, it looks like this is what's source
d in fish:
set --global --export shellHook \"\\$\{DIRENV_IN_ENVRC\}\"\
And we can confirm:
$ string escape -- '"${DIRENV_IN_ENVRC}"\\n' | string replace --all -- \$ \\\$ | string replace --all -- \\n \n
\"\\$\{DIRENV_IN_ENVRC\}\"\
I'm not actually sure what the string replace --all \$ \\\$
bit is for; maybe it's relevant for other lines?
A lot of tools still don't have fish
completions but do have bash
completions. It would be cool to be able to write something like this in config.fish
:
replay source /usr/local/etc/bash_completion.d/flutter.bash
to source bash
completions.
Minimal example:
set PATH "(foo)" $PATH
replay 'PATH=bar:$PATH'
The problem seems to be on Line 33, which will yield the string set PATH (foo) ...
.
This particular issue could be fixed by replacing Line 33 with the following:
string replace --all ')' '\)' (string replace --all '(' '\(' (string replace --all : " " "set $name $value"))
Not sure whether this is the best solution, though.
I'm using bax to source nix on a Mac. I have this:
if test -e '/Users/viktor/.nix-profile/etc/profile.d/nix.sh'
bax source '/Users/viktor/.nix-profile/etc/profile.d/nix.sh'
end
That's a general setup-file for nix that looks like this:
if [ -n "$HOME" ] && [ -n "$USER" ]; then
# Set up the per-user profile.
# This part should be kept in sync with nixpkgs:nixos/modules/programs/shell.nix
NIX_LINK=$HOME/.nix-profile
# Append ~/.nix-defexpr/channels to $NIX_PATH so that <nixpkgs>
# paths work when the user has fetched the Nixpkgs channel.
export NIX_PATH=${NIX_PATH:+$NIX_PATH:}$HOME/.nix-defexpr/channels
# Set up environment.
# This part should be kept in sync with nixpkgs:nixos/modules/programs/environment.nix
export NIX_PROFILES="/nix/var/nix/profiles/default $HOME/.nix-profile"
# Set $NIX_SSL_CERT_FILE so that Nixpkgs applications like curl work.
if [ -e /etc/ssl/certs/ca-certificates.crt ]; then # NixOS, Ubuntu, Debian, Gentoo, Arch
export NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
elif [ -e /etc/ssl/ca-bundle.pem ]; then # openSUSE Tumbleweed
export NIX_SSL_CERT_FILE=/etc/ssl/ca-bundle.pem
elif [ -e /etc/ssl/certs/ca-bundle.crt ]; then # Old NixOS
export NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt
elif [ -e /etc/pki/tls/certs/ca-bundle.crt ]; then # Fedora, CentOS
export NIX_SSL_CERT_FILE=/etc/pki/tls/certs/ca-bundle.crt
elif [ -e "$NIX_LINK/etc/ssl/certs/ca-bundle.crt" ]; then # fall back to cacert in Nix profile
export NIX_SSL_CERT_FILE="$NIX_LINK/etc/ssl/certs/ca-bundle.crt"
elif [ -e "$NIX_LINK/etc/ca-bundle.crt" ]; then # old cacert in Nix profile
export NIX_SSL_CERT_FILE="$NIX_LINK/etc/ca-bundle.crt"
fi
if [ -n "${MANPATH-}" ]; then
export MANPATH="$NIX_LINK/share/man:$MANPATH"
fi
export PATH="$NIX_LINK/bin:$PATH"
unset NIX_LINK
fi
What's failing is:
export NIX_PATH=${NIX_PATH:+$NIX_PATH:}$HOME/.nix-defexpr/channels
The other env is correctly exported but just NIX_PATH is not.
Current workaround is just to do:
if test -e '/Users/viktor/.nix-profile/etc/profile.d/nix.sh'
set -x NIX_PATH $NIX_PATH $HOME/.nix-defexpr/channels
bax source '/Users/viktor/.nix-profile/etc/profile.d/nix.sh'
end
Sorry to report as a bug here, because I think it's just nix preference for bash that's troubling here, but maybe you have some insight?
I've installed bax through fisher and noticed that this message is issued whenever i run fisher
to update all installed fish packages. I'm pretty sure this message has started popping up rather recently. What's the meaning of that message?
I'm running fish 3.1.2 and bax 1.0.0.
Replay is more clear about what this tool does. Bax isn't. That's the only reason. Fisher 4.x makes the transition easy too:
fisher remove jorgebucaran/bax.fish && fisher install jorgebucaran/replay.fish
Use less Awk or no Awk at all. Sorry, Awk. I'm still quite fond of you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.