TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Sd: My Script Directory

128 点作者 shadytrees大约 4 年前

9 条评论

siraben大约 4 年前
One issue I&#x27;ve had with personal shell scripts is that the dependencies are often implicit, or command line arguments change, leading to (sometimes silent and critical) behavior. With Nix you can write shell scripts with a nix-shell shebang[0], specify the dependencies and the rest of the script will run with the dependencies satisfied, for instance, this will execute GNU Hello regardless of whether it is already in the path or not<p><pre><code> #! &#x2F;usr&#x2F;bin&#x2F;env nix-shell #! nix-shell --pure -i bash -p &quot;hello&quot; hello </code></pre> a more realistic example is[1] which generates[2], and if necessary, the Nixpkgs revision can be pinned to fix the dependencies in time. This approach also extends across languages and some of my scripts are written in Haskell which is interpreted!<p>The upshot of all this is that you can write reproducible shell scripts as if you had every package in Nixpkgs available to you, and share it easily with others.<p>[0] <a href="https:&#x2F;&#x2F;nix.dev&#x2F;tutorials&#x2F;ad-hoc-developer-environments.html#reproducible-executables" rel="nofollow">https:&#x2F;&#x2F;nix.dev&#x2F;tutorials&#x2F;ad-hoc-developer-environments.html...</a><p>[1] <a href="https:&#x2F;&#x2F;edef.eu&#x2F;~qyliss&#x2F;nix&#x2F;lib&#x2F;gen.sh" rel="nofollow">https:&#x2F;&#x2F;edef.eu&#x2F;~qyliss&#x2F;nix&#x2F;lib&#x2F;gen.sh</a><p>[2] <a href="https:&#x2F;&#x2F;edef.eu&#x2F;~qyliss&#x2F;nix&#x2F;lib&#x2F;" rel="nofollow">https:&#x2F;&#x2F;edef.eu&#x2F;~qyliss&#x2F;nix&#x2F;lib&#x2F;</a>
评论 #26478538 未加载
ggm大约 4 年前
Most instances of the organising principle I find here are amazing. I think &quot;I would never have done it that way&quot; followed almost immediately by &quot;but damn: its good&quot;<p>for comparison: I have ~&#x2F;bin and I don&#x27;t distinguish between compiled and scripted personal commands.
评论 #26470619 未加载
评论 #26469892 未加载
评论 #26471008 未加载
stevekemp大约 4 年前
I used to have very full ~&#x2F;bin, and ~&#x2F;$(hostname), directories. In the end I pared them back and started bundling things together in one binary.<p>The end result is very similar to this approach, I run &quot;sysbox blah&quot;, or &quot;sysbox help&quot;, and use integrated subcommands.<p>Very helpful and makes deployment easy by having only a single binary:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;skx&#x2F;sysbox" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;skx&#x2F;sysbox</a><p>Not bash&#x2F;shell, but similar and useful idea to experiment with.
DangitBobby大约 4 年前
I have my setup so that you can create a shell environment specific to the project associated with the working directory. For example, I can invoke<p><pre><code> edit-env -ds dump-data.sh </code></pre> and it will open a script for editing which will only be available to run in the project&#x27;s directory. It would be callable as the bash function `dump-data`. I&#x27;ve got lots of useful little things like that now that I wouldn&#x27;t necessarily want to be stored in the project&#x27;s VC but that I find useful.
hzhou321大约 4 年前
While the organization seems nice, the organization itself may have a cognition overhead. I find myself often abandon an organization scheme after I spending time perfecting it. Lately I am mostly using aliases to manage my personal scripts and commands. What the aliases does may change from time to time, but the aliases themselves can stabilize. Those aliases that failed to stabilize or can&#x27;t fit into top of my head probably are not worth keeping anyway. I delete them every once a while.
qbasic_forever大约 4 年前
&#x27;personal monorepo&#x27; is what I like to consider this kind of organization. I have templated starter projects, direnv configs, etc. all in a hierarchy of folders in my home.
legacynl大约 4 年前
This is really similar to something I&#x27;ve recently created: <a href="https:&#x2F;&#x2F;github.com&#x2F;simonmeulenbeek&#x2F;Eezy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;simonmeulenbeek&#x2F;Eezy</a> . Although in my project&#x27;s case it&#x27;s scoped to the specific PWD you&#x27;re in.<p>I really like using the folder structure to have &#x27;subcommands&#x27; (i.e. &#x27;sd blog publish&#x27; ). Very neat!
mootzville大约 4 年前
I made a ~&#x2F;bin folder to do something similar, so I don&#x27;t have to mess with any of the PATH stuff, and can just call it like anything else found in a &#x2F;bin dir.<p>EDIT: Oh, and autocomplete works with it by default. Just &#x27;mkdir ~&#x2F;bin&#x27; and you&#x27;re good to go.
评论 #26471462 未加载
grantseltzer大约 4 年前
If you want an actual project for this I use this one: <a href="https:&#x2F;&#x2F;github.com&#x2F;knqyf263&#x2F;pet" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;knqyf263&#x2F;pet</a>