Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cd! is not found in script #500

Closed
jeffdyke opened this issue Nov 7, 2016 · 8 comments
Closed

cd! is not found in script #500

jeffdyke opened this issue Nov 7, 2016 · 8 comments

Comments

@jeffdyke
Copy link

jeffdyke commented Nov 7, 2016

Hello, i have completely blown away my ammonite installation of 0.7.0 and am upgrading to 0.7.8, i have cleared the entire ~/.ammonite directory as well as removing the amm binary, in the shell with the predef.sc downloaded cd! works correctly, in this simple script it gives the following error.

cat TestCd.sc

import ammonite.ops._
import ammonite.ops.ImplicitWd._

cd! root/'Users/'jeff
amm TestCd.sc
Compiling TestCd.sc
TestCd.sc:4: not found: value cd
val res_2 = cd! root/'Users/'jeff
            ^
Compilation Failed
amm
Loading...
Welcome to the Ammonite Repl 0.7.8
(Scala 2.11.8 Java 1.8.0_101)

I know this will be simple and it seems odd that it compiles in other scripts, before and after the clearing of the cache, so that is when i reduced my issue to this simple set of commands and in this case i likely do not need ImplicitWd._

Thanks!
Jeff

@jeffdyke
Copy link
Author

jeffdyke commented Nov 8, 2016

not surprising, but this works, but fails later when you try to use % or %% b/c of ambiguous Implicits

cat test.sc

#!/usr/bin/env amm
interp.load.ivy("com.lihaoyi" %% "ammonite-shell" % ammonite.Constants.version)
@
val shellSession = ammonite.shell.ShellSession()
import shellSession._
import ammonite.ops._
import ammonite.ops.ImplicitWd._
cd! root/'src/'code
println(wd) // "/src/code"

I just want to know if i can use cd! in scripts and if i can't, why and how do i work around this, cd'ing into directories is critical for scripts especially a build script, which is what i'm using Ammonite for mostly.

Thanks
Jeff

@jeffdyke
Copy link
Author

jeffdyke commented Nov 9, 2016

Thanks for the fix on the ambiguous imports. Do you have any comments on the original issue? This was simply a hack to try to get around the issue temporarily. This is reproducible on a completely new machine after installing 0.7.9 Thanks!

@jeffbondlink
Copy link

Sorry should have written about this a while ago, the fix for this, at least one without a code change is to create a predefScript.sc that can look identical to predef.sc minus the instantiation of the repl(last line as of 0.8.0). This has been working nicely on 0.8.0. For people interested in where this information is, you can dig into the Internals Documentation, specifically: (predef)[https://github.com/lihaoyi/Ammonite/blob/master/internals-docs/predef.md]

Thanks @lihaoyi and contributors for a very helpful product. Please feel free to close this as i don't believe i can.

@lihaoyi
Copy link
Member

lihaoyi commented Apr 30, 2017

cd isn't a member of ammonite.ops; if you want to perform operations in a different directory, define a val newPath = ... and use that in your operations. cd is only available as part of the ammonite shell, as described in http://www.lihaoyi.com/Ammonite/#Ammonite-Shell

@lihaoyi lihaoyi closed this as completed Apr 30, 2017
@jeffdyke
Copy link
Author

jeffdyke commented May 1, 2017

Thanks but the real issue, and it was solved in other ways in the change in behaviour between 0.7.6 and 0.8.0, from memory, responding only so if people try to upgrade

@gnoireaux
Copy link

gnoireaux commented Jun 7, 2019

cd is only available as part of the ammonite shell, as described in http://www.lihaoyi.com/Ammonite/#Ammonite-Shell

Is there an imperative technical reason for ammonite-shell and ammonite-script to differ?
Changing directories is quite basic for scripting.
Hard work was invested in making the repl nice and accessible and concise, why squander it by depriving ammonite-script from cd ?

@jeffdyke
Copy link
Author

jeffdyke commented Jun 10, 2019

@gnoireaux - i realize this does not answer your inquiry, but as i use cd! quite often in ammonite scripts, i thought i'd share. I started with importing it, import ammonite.shell._ directly inside the script, but then moved to adding a predefScript.sc in ~/.ammonite/that contains everything the shell does except for configuring the shell and it works very well. I've been using ammonite for a bash replacement where i need more control/safety, socd` was an absolute requirement.

interp.load.ivy(
  "com.lihaoyi" %
  s"ammonite-shell_${scala.util.Properties.versionNumberString}" %
  ammonite.Constants.version
)
@
val shellSession = ammonite.shell.ShellSession()
import shellSession._
import ammonite.ops._
import ammonite.shell._

There could probably be less in this file, but ... if it ain't broke...

@jeffdyke
Copy link
Author

whoops i guess i basically said the same above, oh well now it's states exactly what i have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants