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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: Can I see your scripts?

374 点作者 fastily将近 3 年前
A few weeks ago, I asked if I could see your cheatsheets (<a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=31928736" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=31928736</a>) and I was really impressed by all the high quality responses!<p>Today I&#x27;m asking about your scripts.<p>Almost every engineer I know has a collection of scripts&#x2F;utilities for automating ${something}. I&#x27;m willing to bet that HN users have some of the most interesting scripts on the internet.<p>So that said, could I please see your scripts?<p>I&#x27;ll go first: <a href="https:&#x2F;&#x2F;github.com&#x2F;fastily&#x2F;autobots" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fastily&#x2F;autobots</a>

144 条评论

hoechst将近 3 年前
Not really a script, but a `.ssh&#x2F;config` to automatically deploy parts of my local cli environment to every server i connect to (if username and ip&#x2F;hostname matches my rules).<p>On first connect to a server, this sync all the dotfiles i want to a remote host and on subsequent connects, it updates the dotfiles.<p>Idk if this is &quot;special&quot;, but I haven&#x27;t seen anyone else do this really and it beats for example ansible playbooks by being dead simple.<p><pre><code> Match Host 192.168.123.*,another-example.org,*.example.com User myusername,myotherusername ForwardAgent yes PermitLocalCommand yes LocalCommand rsync -L --exclude .netrwhist --exclude .git --exclude .config&#x2F;iterm2&#x2F;AppSupport&#x2F; --exclude .vim&#x2F;bundle&#x2F;youcompleteme&#x2F; -vRrlptze &quot;ssh -o PermitLocalCommand=no&quot; %d&#x2F;.&#x2F;.screenrc %d&#x2F;.&#x2F;.gitignore %d&#x2F;.&#x2F;.bash_profile %d&#x2F;.&#x2F;.ssh&#x2F;git_ed25519.pub %d&#x2F;.&#x2F;.ssh&#x2F;authorized_keys %d&#x2F;.&#x2F;.vimrc %d&#x2F;.&#x2F;.zshrc %d&#x2F;.&#x2F;.config&#x2F;iterm2&#x2F; %d&#x2F;.&#x2F;.vim&#x2F; %d&#x2F;.&#x2F;bin&#x2F; %d&#x2F;.&#x2F;.bash&#x2F; %r@%n:&#x2F;home&#x2F;%r</code></pre>
评论 #32469119 未加载
评论 #32470350 未加载
评论 #32469948 未加载
评论 #32470367 未加载
评论 #32472885 未加载
评论 #32524047 未加载
评论 #32496464 未加载
评论 #32474127 未加载
评论 #32470319 未加载
评论 #32469213 未加载
评论 #32470719 未加载
评论 #32499290 未加载
asicsp将近 3 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;command_help&#x2F;blob&#x2F;master&#x2F;ch" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;command_help&#x2F;blob&#x2F;master&#x2F;c...</a><p>Command help, inspired by <a href="http:&#x2F;&#x2F;explainshell.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;explainshell.com&#x2F;</a> to extract help text from builtin commands and man pages. Here&#x27;s an example:<p><pre><code> $ ch ls -AXG ls - list directory contents -A, --almost-all do not list implied . and .. -X sort alphabetically by entry extension -G, --no-group in a long listing, don&#x27;t print group names </code></pre> ---<p><a href="https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;regexp-cut&#x2F;blob&#x2F;main&#x2F;rcut" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;regexp-cut&#x2F;blob&#x2F;main&#x2F;rcut</a> is another - uses awk to provide cut like syntax for field extraction. After writing this, I found commands like `hck`, `tuc` written in Rust that solves most of the things I wanted.
评论 #32569655 未加载
评论 #32468368 未加载
评论 #32471038 未加载
评论 #32469137 未加载
tpoacher将近 3 年前
I have a nice little script for managing &quot;MISC&quot; packages, which stands for &quot;Manually Installed or Source Compiled&quot;.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;tpapastylianou&#x2F;misc-updater" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tpapastylianou&#x2F;misc-updater</a><p>In full honesty, I&#x27;m as proud of the &quot;MISC&quot; acronym as of the script itself. :p<p>I&#x27;m secretly hoping the acronym catches on for referring to any stuff outside the control of a system&#x27;s standard package management.
评论 #32472992 未加载
评论 #32607143 未加载
评论 #32476883 未加载
评论 #32471031 未加载
评论 #32472832 未加载
评论 #32472487 未加载
sshine将近 3 年前
I&#x27;ve pair-programmed a lot this year, and some of my colleagues tend to like the &quot;Co-authored-by: ...&quot; message because they like that due attribution is given regardless of who was in control of the keyboard.<p>I eventually got tired of writing that manually, so I wrote a small<p><pre><code> git co-commit --thor ... </code></pre> that works just like &#x27;git commit&#x27;, except it adds another line to the commit message template.<p>Placing it in e.g. ~&#x2F;bin&#x2F;git-co-commit and having ~&#x2F;bin in your $PATH will enable it as a git sub-command.<p>I&#x27;ve never had a use for this before, and I don&#x27;t think I&#x27;ll need it much beyond this team, but this was my first git sub-command that wasn&#x27;t trivially solvable by existing command parameters (that I know of).<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;sshine&#x2F;d5a2986a6fc377b440bc8aa096037ef0" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;sshine&#x2F;d5a2986a6fc377b440bc8aa096037...</a>
评论 #32468460 未加载
评论 #32471493 未加载
评论 #32529873 未加载
评论 #32496125 未加载
评论 #32468589 未加载
WithinReason将近 3 年前
AutoHotkey script, pressing <i>Caps Lock+Left Mouse Button</i> simulates 50 mouse clicks per second until the left mouse button is pressed:<p><pre><code> ~LButton up:: if (GetKeyState(&quot;CapsLock&quot;, &quot;P&quot;)) { while(!GetKeyState(&quot;LButton&quot;, &quot;P&quot;)){ MouseClick, left sleep 20 } } return </code></pre> Useful in situations when you need to click a lot :)<p>Also a bookmarklet that you use to turn any page dark with a click:<p><pre><code> javascript:document.querySelectorAll(&#x27;\*&#x27;).forEach(e=&gt;e.setAttribute(&#x27;style&#x27;,&#x27;background-color:#222;background-image:none;color:#&#x27;+(&#x2F;^A|BU&#x2F;.test(e.tagName)?&#x27;36c;&#x27;:&#x27;eee;&#x27;)+e.getAttribute(&#x27;style&#x27;))) </code></pre> From here: <a href="https:&#x2F;&#x2F;github.com&#x2F;x08d&#x2F;222" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;x08d&#x2F;222</a>
评论 #32469022 未加载
评论 #32468344 未加载
评论 #32468716 未加载
bwhmather将近 3 年前
I use this script, saved as `rerun`, to automatically re-execute a command whenever a file in the current directory changes:<p><pre><code> #!&#x2F;usr&#x2F;bin&#x2F;sh while true; do reset; &quot;$@&quot;; inotifywait -e MODIFY --recursive . done </code></pre> For example, if you invoke `rerun make test` then `rerun` will run `make test` whenever you save a file in your editor.
评论 #32469184 未加载
评论 #32476671 未加载
calvinmorrison将近 3 年前
Okay it&#x27;s 2022 and you still don&#x27;t want to run nepomunk, a holistic semantic filesystem approach never happened and you&#x27;re stuck with a million files in your Download folder, home folder etc.<p>So I use this script to give me a nice work environment, based on each day.<p>Every time you open bash, it&#x27;ll drop you into today&#x27;s directory. (~&#x2F;work&#x2F;year&#x2F;month&#x2F;day&#x2F;)<p>When I think about stuff it&#x27;s like.. oh yeah I worked on that last week, last year, etc - the folder structure makes this a lot easier, and you can just write &#x27;notes&#x27; or &#x27;meeting-with-joe&#x27; and you know the ref date.<p>For your bashrc:<p><pre><code> alias t=&#x27;source &#x2F;path&#x2F;to&#x2F;today&#x27; t </code></pre> Now every day you&#x27;ll know what you worked on yesterday!<p><pre><code> # this is where you&#x27;ll get dropped by default. calvin@bison:~&#x2F;work&#x2F;2022&#x2F;07&#x2F;10$ calvin@bison:~&#x2F;work&#x2F;2022&#x2F;07&#x2F;10$ ls WardsPerlSimulator.pl calvin@bison:~&#x2F;work&#x2F;2022&#x2F;07&#x2F;10$ cd ..; ls; 01 02 04 05 06 07 08 09 10 calvin@bison:~&#x2F;work&#x2F;2022&#x2F;07$ cd ..; ls 01 02 03 04 05 06 07 calvin@bison:~&#x2F;work&#x2F;2022$ cd ..; ls 2021 2022 </code></pre> additionally you&#x27;ll get a shortcut, you can type &#x27;t&#x27; as a bash fn, or go to ~&#x2F;t&#x2F; which is symlinked and updated everytime you run today (which is everytime you open bash or hit &#x27;t&#x27;. this is useful if you want to have Firefox&#x2F;Slack&#x2F;whatever always save something in your &#x27;today&#x27; folder.<p><a href="https:&#x2F;&#x2F;git.ceux.org&#x2F;today.git&#x2F;" rel="nofollow">https:&#x2F;&#x2F;git.ceux.org&#x2F;today.git&#x2F;</a>
评论 #32468813 未加载
评论 #32468852 未加载
cormorant将近 3 年前
Not exactly a script, but I have a UserStyle applied to Hacker News (using Stylus: &lt;<a href="https:&#x2F;&#x2F;addons.mozilla.org&#x2F;en-US&#x2F;firefox&#x2F;addon&#x2F;styl-us&#x2F;" rel="nofollow">https:&#x2F;&#x2F;addons.mozilla.org&#x2F;en-US&#x2F;firefox&#x2F;addon&#x2F;styl-us&#x2F;</a>&gt;). Here are the best bits:<p>1. Preserve single newlines that people typed in: Often people hit Return only once, and their intended formatting becomes a wall of text. Hacker News preserves the newline in the HTML.<p><pre><code> .commtext { white-space: pre-wrap; } .commtext .reply { white-space: normal; &#x2F;* fix extraneous whitespace caused by first rule *&#x2F; } </code></pre> 2. Vertical lines to visually represent thread depth!<p><pre><code> .ind { background-image: repeating-linear-gradient(to right, transparent 0px 39px, rgba(204, 204, 204, 1.0) 39px 40px); }</code></pre>
评论 #32475428 未加载
dom111将近 3 年前
Similar to most other posters, I have a dotfiles repo, most of it isn&#x27;t particularly novel, but I have a light wrapper around `git` that after a successful clone, will add custom identity information to `.git&#x2F;config` so when I commit, I won&#x27;t inadvertently use my work author string vs my personal author string:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;dom111&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;bin&#x2F;git" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dom111&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;bin&#x2F;git</a><p>which when combined with files like:<p><pre><code> $cat ~&#x2F;.gitidentities&#x2F;github.com [user] name = dom111 email = dom111@users.noreply.github.com </code></pre> means I don&#x27;t accidentally leak email addresses etc<p>Also, not entirely related, but I wrote a small tool to add some animated GIFs to scripts: <a href="https:&#x2F;&#x2F;dom111.github.io&#x2F;gif-to-ansi&#x2F;" rel="nofollow">https:&#x2F;&#x2F;dom111.github.io&#x2F;gif-to-ansi&#x2F;</a>
zffr将近 3 年前
I use a custom git alias `git recent` almost every day. It shows you the the most recent branches you have worked on. This is useful for when you are are trying to find a branch you have worked on recently, but forgot its name.<p>To use this alias, make an executable file called `git-recent` with the following contents and ensure it is in your `$PATH`<p><pre><code> git for-each-ref \ --sort=-committerdate refs&#x2F;heads&#x2F; \ --format=&#x27;%(HEAD) %(color:red)%(objectname:short)%(color:reset) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))&#x27; </code></pre> Here&#x27;s a redacted example of the output looks like<p><pre><code> * fc924a7e68 team&#x2F;name&#x2F;feature-2 - save - My Name (4 days ago) 2fed1acfac team&#x2F;name&#x2F;feature-1 - add test - My Name (3 weeks ago) 4db4d4ac77 main - Remove changes (#22397) - My Name (6 weeks ago)</code></pre>
评论 #32470850 未加载
评论 #32479978 未加载
评论 #32470901 未加载
elondaits将近 3 年前
Not that long ago I was maintaining around 30 Drupal (popular PHP CMS) websites for different clients, on different ISPs.<p>I made a CLI utility for automating certain operations I was doing all the time: rsync of sources (push or pull), db backup &#x2F; rollback, copying the local db to the remote server or back, etc. The utility looked for a dotfile in the project directory to get things like the remote server address, remote project path, etc.<p>The tool served several purposes:<p>- Executing auxiliary tools (rsync, mysqldump, drush) with the right parameters, without requiring me to remember them.<p>- Storing (non-secret) information about the remote environment(s) in the project directory.<p>- Some dangerous operations (e.g. copying the local db to the remote server) were prohibited unless the dotfile explicitly enabled them. Some sites were only edited on dev and then pushed to production, but some had user data that should never be overwritten.<p>- When running rsync of sources the tool always did a dry-run first, and then required entering a randomly generated 4-letter code to execute them... so I would have to stop and think and didn&#x27;t deploy by mistake.<p>This tool is too rough for sharing it with the general public... but I consider it one of my greatest professional achievements because it saved me a lot of mental effort and stress over the years, quite a bit of time, prevented me from shooting myself in the foot, and forced me to use proper workflows every time instead of winging it. It required a small investment of time and some foresight... but my philosophy is that my work should be to build tools to replace me, and that was a step in that direction.
评论 #32497033 未加载
junon将近 3 年前
<p><pre><code> function ccd { mkdir -p &quot;$1&quot; &amp;&amp; cd &quot;$1&quot; } </code></pre> Biggest timesaving script I&#x27;ve ever included in my arsenal.
评论 #32469517 未加载
评论 #32470505 未加载
评论 #32469858 未加载
评论 #32470304 未加载
leibnitz27将近 3 年前
Not mine, and not ..... really.... serious.... but someone has to mention the greatest work scripts ever :<p><a href="https:&#x2F;&#x2F;github.com&#x2F;NARKOZ&#x2F;hacker-scripts" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;NARKOZ&#x2F;hacker-scripts</a>
sunaurus将近 3 年前
Related to writing scripts on Mac OS, I highly recommend rumps (<a href="https:&#x2F;&#x2F;rumps.readthedocs.io" rel="nofollow">https:&#x2F;&#x2F;rumps.readthedocs.io</a>) to show anything you want in your status bar.<p>For example, I have one script that uses rumps to show how many outdated homebrew packages I have (and also as a convenient shortcut to update those packages in the dropdown menu). I also have a second script that uses it to show a counter for open pull requests that I need to review (with links to individual PRs in the dropdown menu). It&#x27;s great!<p>Result looks like this: <a href="https:&#x2F;&#x2F;imgur.com&#x2F;yy6GlYk.jpg" rel="nofollow">https:&#x2F;&#x2F;imgur.com&#x2F;yy6GlYk.jpg</a>
评论 #32468859 未加载
评论 #32529947 未加载
samatman将近 3 年前
Here&#x27;s a shell script for moving files in git between repos, preserving the history, and following that history through the file being renamed:<p><pre><code> git-move src&#x2F;afile.c src&#x2F;bfile.c src&#x2F;cfile.c ..&#x2F;destination&#x2F;repo </code></pre> <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;mnemnion&#x2F;87b51dc8f15af3242204472391f3bf59" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;mnemnion&#x2F;87b51dc8f15af3242204472391f...</a>
评论 #32468884 未加载
grandpoobah将近 3 年前
Bank reconcilliation in Xero has no &quot;auto match if reference and date are the same&quot; option, so I (very crudely) scripted one. It&#x27;ll run until it encounters a mismatch (which for the company I work for is basically never). Paste into console.<p>function go() {<p><pre><code> let line = document.querySelector(&#x27;#statementLines .line&#x27;); if (line) { let leftAndRight = line.querySelectorAll(&#x27;.statement&#x27;); let left = leftAndRight[0]; let right = leftAndRight[1]; if (right.hasClassName(&#x27;matched&#x27;)) { let leftDetails = left.querySelectorAll(&#x27;.info .details-container .details span&#x27;); let leftDate = leftDetails[0].textContent; let leftReference = leftDetails[1].textContent; let rightDetails = right.querySelectorAll(&#x27;.info .details-container .details span&#x27;); let rightDate = rightDetails[0].textContent; let rightReference = rightDetails[2].textContent; rightReference = rightReference.replace(&#x27;Ref: &#x27;, &#x27;&#x27;); if (Date.parse(leftDate).getTime() == Date.parse(rightDate).getTime() &amp;&amp; leftReference.toLowerCase() == rightReference.toLowerCase()) { var okButton = line.querySelector(&quot;.ok .okayButton&quot;); console.log(leftReference); okButton.click(); var waiter = function () { if (line.parentNode == null) { go(); } else { setTimeout(waiter, 50); } }; setTimeout(waiter, 50); } else { console.log(&quot;Details dont match&quot;); } } else { console.log(&quot;Line not matched&quot;); } } else { console.log(&quot;No line found&quot;); } </code></pre> }<p>setTimeout(go, 100);
评论 #32469294 未加载
评论 #32469002 未加载
xrd将近 3 年前
I just reviewed my own set of scripts in bin and don&#x27;t feel I&#x27;ve got anything to contribute.<p>BUT, this thread is so special because it feels like this is the stuff you only get to see when you sit down at a co-worker&#x27;s desk and watch them type something and then say &quot;WHAT? HOW COOL!&quot;<p>I miss that part now that it is all remote work. :(
Nephx将近 3 年前
Simple command line utility to display charging (or discharging) rate in watts on linux. You might have to modify battery_directory and the status&#x2F;current_now&#x2F;voltage_now names based on laptop brand, but Lenovo, Dell and Samsung seems to use this convention.<p><pre><code> #!&#x2F;usr&#x2F;bin&#x2F;python3 battery_directory = &quot;&#x2F;sys&#x2F;class&#x2F;power_supply&#x2F;BAT1&#x2F;&quot; with open(battery_directory + &quot;status&quot;, &quot;r&quot;) as f: state = f.read().strip() with open(battery_directory + &quot;current_now&quot;, &quot;r&quot;) as f: current = int(f.read().strip()) with open(battery_directory + &quot;voltage_now&quot;, &quot;r&quot;) as f: voltage = int(f.read().strip()) wattage = (voltage &#x2F; 10**6) * (current &#x2F; 10**6) wattage_formatted = f&quot;{&#x27;-&#x27; if state == &#x27;Discharging&#x27; else &#x27;&#x27;}{wattage:.2f}W&quot; if state in [&quot;Charging&quot;, &quot;Discharging&quot;, &quot;Not charging&quot;]: print(f&quot;{state}: {wattage_formatted}&quot;) </code></pre> Output:<p>Charging: 32.15W<p>Discharging: -5.15W
评论 #32470667 未加载
Sirikon将近 3 年前
My workstation setup, both for Linux and MacOS, is in the following repository: <a href="https:&#x2F;&#x2F;github.com&#x2F;sirikon&#x2F;workstation" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sirikon&#x2F;workstation</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;sirikon&#x2F;workstation&#x2F;blob&#x2F;master&#x2F;src&#x2F;cli&#x2F;commands&#x2F;install.ts" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sirikon&#x2F;workstation&#x2F;blob&#x2F;master&#x2F;src&#x2F;cli&#x2F;c...</a><p>For Linux, it can install and configure everything I need when launched on a clean Debian installation. apt repositories, pins and packages; X11, i3, networking, terminal, symlinking configuration of many programs to Dropbox or the repository itself... The idea is to have my whole setup with a single command.<p>For Mac, it installs programs using brew and sets some configurations. Mac isn&#x27;t my daily driver so the scripts aren&#x27;t as complete.<p>Also there are scripts for the terminal to make my life easier. Random stuff like killing any gradle process in the background, upgrading programs that aren&#x27;t packetized on APT, backing up savegames from my Anbernic, etc. <a href="https:&#x2F;&#x2F;github.com&#x2F;sirikon&#x2F;workstation&#x2F;tree&#x2F;master&#x2F;src&#x2F;shell" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sirikon&#x2F;workstation&#x2F;tree&#x2F;master&#x2F;src&#x2F;shell</a><p>And more programs for common use, like screenshots, copying Stripe test cards into the clipboard, launching android emulators without opening Android Studio, etc. <a href="https:&#x2F;&#x2F;github.com&#x2F;sirikon&#x2F;workstation&#x2F;tree&#x2F;master&#x2F;src&#x2F;bin" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sirikon&#x2F;workstation&#x2F;tree&#x2F;master&#x2F;src&#x2F;bin</a>
impalallama将近 3 年前
A bash script to open up the current git branch in my browser.<p>Use it everyday. Great because my company has multiple git submodules in any given project and I can use this to watch for pipeline failures and the like.<p><pre><code> x=$(git config --local remote.origin.url|sed -n &#x27;s#.*&#x2F;\([^.]*\)\.git#\1#p&#x27;) y=$(git symbolic-ref --short HEAD) url=&quot;https:&#x2F;&#x2F;git.thecompany.com&#x2F;thecompany&#x2F;$x&#x2F;tree&#x2F;$y&quot; $(open -a &quot;firefox developer edition&quot; &quot;$url&quot;</code></pre>
评论 #32477370 未加载
评论 #32538727 未加载
garfieldnate将近 3 年前
I use termdown to run timers in my terminal. Back when we only had a pressure cooker and couldn&#x27;t afford an automatic rice cooker, I wrote a bash function &quot;rice&quot; that would give instructions for cooking it in the pressure cooker. Kinda silly in retrospect, but it did ease the pain of being broke a bit:<p><pre><code> function alarm_forever() { # play one part of the track at a time so that this function can be killed any time while :; do afplay --time .72 ~&#x2F;sounds&#x2F;alarm.mp3; done } function alarm_until_input() { alarm_forever &amp; pid=$!; read -n 1 -p &quot;$*&quot;; kill -9 $pid; } # pip install termdown function timer { termdown $@; alarm_until_input &quot;[Press any key to stop]&quot; } alias alarm=&quot;timer&quot; # TODO: ask if user soaked the rice first function rice { echo &quot;1. Wash rice. Place in pressure cooker with 1-1 water-rice ratio.&quot; echo &quot;2. Place the pressure cooker on the stove on high.&quot; read -n 1 -p &quot;3. When the pressure pot starts whistling, press any key to start the timer.&quot; termdown --title &quot;Tweet!&quot; 2m alarm_until_input &quot;4. Take pot off heat and press any key.&quot; termdown --title &quot;RICE&quot; 11m alarm_until_input &quot;5. Open the pot and stir the rice immediately.&quot; alarm_until_input &quot;6. Eat!&quot; }</code></pre>
GOATS-将近 3 年前
I used to clip tons of videos for highlight reels, which was made a lot quicker with this snippet.<p><pre><code> clip_video () { ffmpeg -ss &quot;$2&quot; -i &quot;$1&quot; -t &quot;$3&quot; -c copy &quot;$4&quot; } </code></pre> Used like so:<p><pre><code> clip_video filename.mp4 start_point duration output.mp4</code></pre>
评论 #32471135 未加载
trevithick将近 3 年前
A bloated script to automate creation of an Arch Linux Qemu VM. The subscript that runs in the VM is useful by itself for setting up a new Arch installation.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;trevorgross&#x2F;installarch&#x2F;blob&#x2F;main&#x2F;installarch.sh" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;trevorgross&#x2F;installarch&#x2F;blob&#x2F;main&#x2F;install...</a><p>It&#x27;s a personal tool that just kept growing. Probably amateurish by HN standards, but then, I&#x27;m an amateur. Yes, I could simply copy a disk image, but that&#x27;s no fun.
dijit将近 3 年前
My scripts are usually for work so they don&#x27;t make sense outside of that.<p>One I was particularly proud of&#x2F;disgusted by was one that allowed me to jump around a network with a single command despite access being gated by regional jumphosts..<p>You are warned: <a href="https:&#x2F;&#x2F;git.drk.sc&#x2F;-&#x2F;snippets&#x2F;107" rel="nofollow">https:&#x2F;&#x2F;git.drk.sc&#x2F;-&#x2F;snippets&#x2F;107</a><p>Another script I wrote for our devs to get access to MySQL in production on GCP; the intent was for the script to be executable only by root and allow sudo access to only this script: that means also &#x27;&#x27;chmod ugo-rwx gcloud&#x27;&#x27; too though: <a href="https:&#x2F;&#x2F;git.drk.sc&#x2F;-&#x2F;snippets&#x2F;98" rel="nofollow">https:&#x2F;&#x2F;git.drk.sc&#x2F;-&#x2F;snippets&#x2F;98</a><p>I have another script to generate screenshots from grafana dashboards since that functionality was removed from grafana itself (<a href="https:&#x2F;&#x2F;github.com&#x2F;grafana&#x2F;grafana&#x2F;issues&#x2F;18914" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;grafana&#x2F;grafana&#x2F;issues&#x2F;18914</a>): <a href="https:&#x2F;&#x2F;git.drk.sc&#x2F;-&#x2F;snippets&#x2F;66" rel="nofollow">https:&#x2F;&#x2F;git.drk.sc&#x2F;-&#x2F;snippets&#x2F;66</a><p>Another time I got annoyed that Wayland&#x2F;Sway would relabel my screens on successive disconnect&#x2F;reconnects (IE my right screen could be DP-1 or DP-7 or anything in between randomly); so I wrote a docking script which moves the screens to the right place based on serial number: <a href="https:&#x2F;&#x2F;git.drk.sc&#x2F;-&#x2F;snippets&#x2F;74" rel="nofollow">https:&#x2F;&#x2F;git.drk.sc&#x2F;-&#x2F;snippets&#x2F;74</a>
评论 #32468231 未加载
scottLobster将近 3 年前
Going to use this opportunity to spam ShellCheck, because it has historically saved me dozens of hours catching many silent Bash scripting errors and just making my scripts more robust&#x2F;warning me of obscure edge cases:<p><a href="https:&#x2F;&#x2F;www.shellcheck.net&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.shellcheck.net&#x2F;</a>
评论 #32469998 未加载
评论 #32472131 未加载
mateuszbuda将近 3 年前
I have a script for concurrent web scraping: <a href="https:&#x2F;&#x2F;github.com&#x2F;mateuszbuda&#x2F;webscraping-benchmark" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mateuszbuda&#x2F;webscraping-benchmark</a> It takes a file with urls and scrapes the content. For more demanding websites it can use web scraping API that handles rotating proxies. I add some logic to process the output as needed.
ebfe1将近 3 年前
Since everyone here like scripting, May I suggest, if you have not used it already, checkout Xbar (<a href="https:&#x2F;&#x2F;xbarapp.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;xbarapp.com&#x2F;</a>) for Mac and Argos (<a href="https:&#x2F;&#x2F;argos-scripts.github.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;argos-scripts.github.io&#x2F;</a>) for Linux.<p>I have used these 2 on my machines for the last 4 years and writing tons of script for myself, here are a few:<p>- Displaying internet&#x2F;internal ip and allow me to click it to put in clipboard<p>- taskwarrior<p>- Simple conversion script that take my clipboard &amp; encode&#x2F;decode in base64, hex, url encoding, convert epoch to UTC,<p>- &quot;auto type&quot; my clipboard by simulating keystrokes- particular useful for pasting text into terminal that disable clipboard<p>- An incident response switch that would trigger a script to take screenshot every 5 seconds when my mouse moves, reduce image quality and save it to a folder in my homedrive. Another script will GPG encrypt it at the end of the day so i can go back and get screenshot or look back at incident if needed.
评论 #32477111 未加载
hunterb123将近 3 年前
JS snippet to sort and return Play Store app reviews by helpfulness:<p><pre><code> var nodes = [...document.querySelectorAll(&#x27;\*[aria-label=&quot;Number of times this review was rated helpful&quot;]&#x27;)]; nodes.sort((a, b) =&gt; (parseInt(b.innerText) || 0) - (parseInt(a.innerText) || 0)); nodes.map(e =&gt; ([ parseInt(e.innerText) || 0, e.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].textContent.toString().trimStart(), ]));</code></pre>
dcolkitt将近 3 年前
Here&#x27;s one I wrote a few years back, that I&#x27;m quite fond of. It turns any arbitrary directory tree with individual executables into a &quot;git [X] [Y]&quot; style shell command.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;Mister-Meeseeks&#x2F;subcmd&#x2F;blob&#x2F;master&#x2F;subcmd" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Mister-Meeseeks&#x2F;subcmd&#x2F;blob&#x2F;master&#x2F;subcmd</a>
评论 #32471513 未加载
HeckFeck将近 3 年前
Somewhat boring, but I wrote a shell script to tar and gzip my home directory and then rsync it to a NAS drive.<p>It can be configured to exclude certain directories (.cache and Downloads being likely contenders). Also, it can read in config files so it can backup other directories.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;lordfeck&#x2F;feckback" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lordfeck&#x2F;feckback</a>
SuperCuber将近 3 年前
Dead simple but serves me extremely well, and I haven&#x27;t seen anyone do it:<p><pre><code> cd () { builtin cd &quot;$@&quot; || return $? ls --my-usual-flags }</code></pre>
评论 #32469650 未加载
评论 #32470751 未加载
superfamicom将近 3 年前
On macOS this can be really useful, change the current terminal to the top most folder in Finder, do not recall where it came from:<p><pre><code> # Change to the Front Folder open in Finder function ff { osascript -e &#x27;tell application &quot;Finder&quot;&#x27;\ -e &#x27;if (0 &lt; (count Finder windows)) then&#x27;\ -e &#x27;set finderpath to get target of the front window as alias&#x27;\ -e &#x27;else&#x27;\ -e &#x27;set finderpath to get desktop as alias&#x27;\ -e &#x27;end if&#x27;\ -e &#x27;get POSIX path of finderpath&#x27;\ -e &#x27;end tell&#x27;;};\ function cdff { cd &quot;`ff $@`&quot; || exit; };</code></pre>
aendruk将近 3 年前
Old habit breaker:<p><pre><code> git() { if [[ &quot;$1&quot; == &#x27;checkout&#x27; ]]; then echo &#x27;Reminder: Use `git switch` or `git restore` instead.&#x27; &gt;&amp;2 fi command git &quot;$@&quot; }</code></pre>
评论 #32538535 未加载
paskozdilar将近 3 年前
I&#x27;ve often encountered dependency issues on Ubuntu. One time, while dealing with NVidia&#x2F;CUDA, running `apt-get -y install cuda` complained about some missing dependency. I recursively went through the error messages and installed every missing dependency manually, and it worked, but it took me a long time and a lot of typing.<p>Then I wrote a script that does that automatically:<p><pre><code> #!&#x2F;usr&#x2F;bin&#x2F;env bash main() { local package=&quot;$1&quot; if [ -z &quot;$package&quot; ] then echo &quot;usage: $0 PACKAGE&quot; exit 1 fi install_package &quot;$package&quot; } install_package() { local package=&quot;$1&quot; local subpackage if sudo apt-get -y install &quot;$package&quot; then exit 0 else sudo apt-get -y install &quot;$package&quot; \ |&amp; grep &#x27;^ &#x27; \ | sed &#x27;s&#x2F;[^:]*:[^:]*: &#x2F;&#x2F;;s&#x2F; .*&#x2F;&#x2F;;&#x27; \ | { while read subpackage do install_package &quot;$subpackage&quot; done } sudo apt-get -y install &quot;$package&quot; \ &amp;&amp; echo &quot;SUCCESS: $package&quot; \ || echo &quot;FAILURE: $package&quot; fi } main &quot;$@&quot;</code></pre>
评论 #32473541 未加载
alsetmusic将近 3 年前
Here’s a cat function with highlighting for when I’m working on different platforms and might not have the shell configured for syntax highlighting:<p>#!&#x2F;usr&#x2F;bin&#x2F;env bash<p>function shc() { #: cat for shell scripts, source code. #: prints text with line numbers and syntax highlighting. #: accepts input as argument or pipe.<p><pre><code> if [ $# -eq 0 ]; then # arguments equal zero; assume piped input nl | &#x2F;usr&#x2F;local&#x2F;bin&#x2F;pygmentize -l bash # accept piped input, process as source code else case &quot;$1&quot; in -h|--help) printf &quot;%s\n&quot; &quot;shc usage:&quot; &quot; shc [file]&quot; &quot; type [function] | shc&quot; ;; -v|--version) printf &quot;%s\n&quot; &quot;vers 2&quot; ;; *) if [ -f &quot;$1&quot; ]; then # test anything that isn&#x27;t expected flags for file cat &quot;$1&quot; | nl | &#x2F;usr&#x2F;local&#x2F;bin&#x2F;pygmentize -l bash # process file as source code else # if not a file or expected flags, bail printf &quot;%s\n&quot; &quot;error; not the expected input. read shc_func source for more details&quot; fi esac fi }</code></pre>
simzor将近 3 年前
Makes operating AWS CLI against a user with MFA enabled easier<p>---------<p>#!&#x2F;bin&#x2F;sh<p>echo &quot;Store and retrieve session token AWS STS \n\n&quot;<p># Get source profile read -p &quot;Source Profile [&lt;profile_name&gt;]: &quot; source_profile source_profile=${source_profile:-&#x27;&lt;profile_name&gt;&#x27;} echo $source_profile<p># Get destination profile read -p &quot;Destination Profile [&lt;profile_name&gt;-mfa]: &quot; destination_profile destination_profile=${destination_profile:-&#x27;&lt;profile_name&gt;-mfa&#x27;} echo $destination_profile<p>mfa_serial_number=&#x27;arn:aws:iam::&lt;id&gt;:mfa&#x2F;&lt;name&gt;&#x27;<p>echo &quot;\nOTP: &quot; read -p &quot;One Time Password (OTP): &quot; otp<p>echo &quot;\nOTP:&quot; $otp echo &quot;\n&quot;<p>output=$(aws sts get-session-token --profile &lt;profile_name&gt; --serial-number $mfa_serial_number --output json --token-code $otp)<p>echo $output<p>access_key_id=$(echo $output | jq .Credentials.AccessKeyId | tr -d &#x27;&quot;&#x27;) secret_access_key=$(echo $output | jq .Credentials.SecretAccessKey | tr -d &#x27;&quot;&#x27;) session_token=$(echo $output | jq .Credentials.SessionToken | tr -d &#x27;&quot;&#x27;)<p>aws configure set aws_access_key_id $access_key_id --profile=$destination_profile aws configure set aws_secret_access_key $secret_access_key --profile=$destination_profile aws configure set aws_session_token $session_token --profile=$destination_profile<p>echo &quot;Configured AWS for profile&quot; $destination_profile
评论 #32468537 未加载
davisoneee将近 3 年前
This is my autohotkey function, so that Windows gets the same functionality as OSX for cycling through instances of the same app (e.g. multiple firefox instances). Pass 0 or 1 to cycle all apps, or apps on the same desktop.<p><pre><code> !`::CycleCurrentApplication(0) !+`::CycleCurrentApplication(1) WhichMonitorAppIsOn(winId) { WinGetPos, cX, cY, cW, cH, ahk_id %winId% xMid := cX + (cW &#x2F; 2) yMid := cY + (cH &#x2F; 2) SysGet, nMons, MonitorCount Loop, % nMons { ; MsgBox %A_Index% SysGet, tmp, Monitor, %A_Index% withinWidth := (xMid &gt; tmpLeft) &amp;&amp; (xMid &lt; tmpRight) ; MsgBox % tmpLeft . &quot; -&gt; &quot; . tmpRight . &quot;`t&quot; . xMid if (withinWidth == 1) return %A_Index% } } CycleCurrentApplication(same_desktop_only) { WinGet, curID, ID, A curMon := WhichMonitorAppIsOn(curID) WinGetClass, ActiveClass, A WinGet, WinClassCount, Count, ahk_class %ActiveClass% IF WinClassCount = 1 Return Else WinGet, List, List, % &quot;ahk_class &quot; ActiveClass Loop, % List { index := List - A_Index + 1 WinGet, State, MinMax, % &quot;ahk_id &quot; List%index% WinGet, nextID, ID, % &quot;ahk_id &quot; List%index% nextMon := WhichMonitorAppIsOn(nextID) if (same_desktop_only &gt; 0 &amp;&amp; (curMon != nextMon)) continue if (State != -1) ; if window not minimised { WinID := List%index% break } } WinActivate, % &quot;ahk_id &quot; WinID }</code></pre>
acomjean将近 3 年前
I use a short bash&#x2F;perl script to find&#x2F;replace globally in large files. I have to change the search function each time, although I pass in the file name. Its not sophisticated, but its been very useful.<p>The reason I like it is also backs up the original in case I mess up the regex (happens sometimes...)<p><pre><code> #!&#x2F;usr&#x2F;bin&#x2F;env bash perl -i.bak -p -e &#x27;s&#x2F;oldtext&#x2F;newtext&#x2F;g;&#x27; $1</code></pre>
t-3将近 3 年前
I used to have a bunch of scripts, but I compulsively &quot;clean&quot; my backups too often to keep old stuff around. Here&#x27;s my &quot;newterm&quot; script, which I use for launching xterm with tmux:<p><pre><code> #!&#x2F;bin&#x2F;sh if [ $(tmux has-session 2&gt;&#x2F;dev&#x2F;null; echo $?) -eq 0 ]; then if [ $(tmux list-windows -f &#x27;#{window_active_clients}&#x27;) ]; then if [ $(tmux ls | head -n 1 | awk &#x27;{print $2}&#x27;) -le 2 ]; then xterm -e &quot;tmux new-session -f active-pane,ignore-size -t &quot;0&quot; \; new-window&quot; else xterm -e &quot;tmux new-session -f active-pane,ignore-size -t &quot;0&quot; \; select-window -t +2&quot; fi else xterm -e &quot;tmux attach -f active-pane,ignore-size -t &quot;0&quot;&quot; fi else xterm -e tmux new-session -f active-pane,ignore-size fi if [ $(tmux ls | wc -l) -gt 1 ]; then for i in $(tmux ls -F &#x27;#S&#x27; -f &#x27;#{?session_attached,,#S}&#x27; ); do tmux kill-session -t ${i} done fi</code></pre>
评论 #32476173 未加载
withinboredom将近 3 年前
Using my GitHub SSH keys to login as root on my servers: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;withinboredom&#x2F;84067b9662abc1f968dfadfe799cfcb2" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;withinboredom&#x2F;84067b9662abc1f968dfad...</a><p>This can be extended easily, even dynamically creating an account if the user is part of an org, or use libnss-ato to alias the user to a specific account.
falcolas将近 3 年前
For local documentation of libraries (and languages):<p><pre><code> #! &#x2F;bin&#x2F;bash remote_file_path=$1 wget --recursive --level=5 --convert-links --page-requisites --wait=1 --random-wait --timestamping --no-parent ${remote_file_path} </code></pre> And a couple of zshrc functions which make jumping around my filesystem quite snappy. `jump` is aliased to `j`, and `mark` to `m`<p><pre><code> MARKPATH=~&#x2F;.marks function jump { cd -P ${MARKPATH}&#x2F;$1 2&gt; &#x2F;dev&#x2F;null || (echo &quot;No such mark: $1&quot; &amp;&amp; marks) } function mark { mkdir -p ${MARKPATH}; ln -s $(pwd) $MARKPATH&#x2F;$1 } function unmark { rm -i ${MARKPATH}&#x2F;$1 } function marks { ls -l ${MARKPATH} | sed &#x27;s&#x2F; &#x2F; &#x2F;g&#x27; | cut -d&#x27; &#x27; -f9- &amp;&amp; echo } _jump() { local cur=${COMP_WORDS[COMP_CWORD]} COMPREPLY=( $(compgen -W &quot;$( ls $MARKPATH )&quot; -- $cur) ) } complete -F _jump jump </code></pre> (Totally stolen, and fixed up to work in ZSH)
评论 #32470527 未加载
评论 #32470311 未加载
firesloth将近 3 年前
I have a bash function I use to checkout a git branch based on a search string:<p><pre><code> function git-checkout-branch-by-search-string() { local maybe_branch_name maybe_branch_name=$(git branch --sort=-committerdate | grep $1 | head -n 1) if [ -n &quot;$maybe_branch_name&quot; ]; then git checkout &quot;${maybe_branch_name:2}&quot; else echo &quot;Could not find branch matching $1&quot; fi } alias gcos=&quot;git-checkout-branch-by-search-string&quot; </code></pre> Branches often include things like ticket numbers and project keys, so you can do<p><pre><code> $ gcos 1234 </code></pre> and save some typing.<p>I have a pair of fixup commit functions, which make it faster to target fixup commits prior to rebasing:<p><pre><code> function git-commit-fixup() { git commit --fixup &quot;:&#x2F;$*&quot; } function git-add-all-then-git-commit-fixup() { git add . git commit --fixup &quot;:&#x2F;$*&quot; } </code></pre> Long function names that are then assigned to an alias can make it easier to find them later if you forget rarely used ones. That is you can do:<p>$ alias | grep fixup<p>to see the list of relevant aliases and the functions they call.<p>I also have two functions I use like a linear git bisect:<p><pre><code> function git-checkout-parent-commit() { local prev prev=$(git rev-parse HEAD~1) git checkout &quot;$prev&quot; } function git-checkout-child-commit() { local forward forward=$(git-children-of HEAD | tail -1) git checkout &quot;$forward&quot; } function git-children-of() { for arg in &quot;$@&quot;; do for commit in $(git rev-parse $arg^0); do for child in $(git log --format=&#x27;%H %P&#x27; --all | grep -F &quot; $commit&quot; | cut -f1 -d&#x27; &#x27;); do echo $child done done done }</code></pre>
demindiro将近 3 年前
I use this to generate my site:<p><pre><code> #!&#x2F;usr&#x2F;bin&#x2F;env bash for file in `find . -name &#x27;*.md&#x27;`; do output=${file::-3}.html if [[ `date -r &quot;$file&quot; &quot;+%s&quot;` -le `date -r &quot;..&#x2F;$output&quot; &quot;+%s&quot;` ]] then echo &quot;Skipping $file&quot; continue fi mkdir -p ..&#x2F;$(dirname $output) echo Generating $output from $file cat &lt;&lt; EOF &gt; ..&#x2F;$output &lt;!DOCTYPE html&gt; `cat head.html` &lt;body&gt; `cat navigation.html` &lt;main&gt; `pandoc $file` &lt;&#x2F;main&gt; &lt;footer&gt; &lt;span&gt;The content on this page is licensed under the CC BY-ND 4.0&lt;&#x2F;span&gt; &lt;a style=&quot;float:right&quot; href=&quot;&#x2F;md&#x2F;$file&quot;&gt;Source&lt;&#x2F;a&gt; &lt;&#x2F;footer&gt; &lt;&#x2F;body&gt; EOF done;</code></pre>
flobosg将近 3 年前
Not mine and I don’t remember the source, but really useful:<p><pre><code> # Simple calculator function calc() { local result=&quot;&quot; result=&quot;$(printf &quot;scale=10;$*\n&quot; | bc --mathlib | tr -d &#x27;\\\n&#x27;)&quot; # └─ default (when `--mathlib` is used) is 20 # if [[ &quot;$result&quot; == *.* ]]; then # improve the output for decimal numbers printf &quot;$result&quot; | sed -e &#x27;s&#x2F;^\.&#x2F;0.&#x2F;&#x27; `# add &quot;0&quot; for cases like &quot;.5&quot;` \ -e &#x27;s&#x2F;^-\.&#x2F;-0.&#x2F;&#x27; `# add &quot;0&quot; for cases like &quot;-.5&quot;`\ -e &#x27;s&#x2F;0*$&#x2F;&#x2F;;s&#x2F;\.$&#x2F;&#x2F;&#x27; # remove trailing zeros else printf &quot;$result&quot; fi printf &quot;\n&quot; }</code></pre>
评论 #32472299 未加载
muskmusk将近 3 年前
I have my notes in Dendron which is basically a directory of yaml files. I often need to search through the notes so I made the below<p>search_notes() { input=$(rg -v &#x27;(\-\-)|(^\s*$)&#x27; --line-number &#x2F;home&#x2F;user&#x2F;some-dir | fzf --ansi --delimiter : --preview &#x27;batcat --color=always {1} --highlight-line {2}&#x27; --preview-window &#x27;up,60%,border-bottom,+{2}+3&#x2F;3,~3&#x27; | choose -f : 0) if [[$input = &quot;&quot;]]; then else less $input fi }<p>It uses various linux utilities including fzf and batcat(<a href="https:&#x2F;&#x2F;github.com&#x2F;sharkdp&#x2F;bat" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sharkdp&#x2F;bat</a>) to open a terminal with all the places where my query comes up (supporting fuzzy search). Since the workhorses are fzf and ripgrep its is quite fast even for very large directories.<p>So i will do `search_notes postgres authentication`. I can select a line and it will open the file in less. Works like a charm!
ThePhysicist将近 3 年前
I run this simple shell script to make daily incremental backups of my home folder using Borg. It works really well, haven&#x27;t touched it in years [1].<p>1: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;adewes&#x2F;02e8a1f662d100a7ed80627801d0aed0" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;adewes&#x2F;02e8a1f662d100a7ed80627801d0a...</a>
doctorwho42将近 3 年前
To shake it up compared to other responses. I regularly integrate the PyWin32 library into work scripts. Sometimes you just need a way to automate interactions with Windows in those non-dev jobs.<p>The most recent was a script that parsed a financial report and generated multiple emails depending on a set of criteria. Then the user could manual review these emails and press send if everything checks out. The goal of the script was to reduce some of the menial work my financial co-worker was doing. I don&#x27;t have it published on GitHub because it has some internal company info in it. But it worked cleanly, and regularly saves him hours of tedious work.<p>Also I highly recommend EasyGui library for those quick scripts that need user input from people who are not comfortable with a console&#x2F;cmd. Helps make different types of popup windows for user input&#x2F;selection with a few simple lines.
sm_ts将近 3 年前
I can only share a part, since the majority of my scripts reveal much about my system structure (I try to open whatever I can, though; the tedious part of open sourcing a script, is to make it generic&#x2F;configurable):<p><a href="https:&#x2F;&#x2F;github.com&#x2F;64kramsystem&#x2F;openscripts" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;64kramsystem&#x2F;openscripts</a><p>Missed the previous cheatsheet post :) I have a massive collection, which are large enough to be books more than cheatsheets (still, I access and use them as cheatsheets):<p><a href="https:&#x2F;&#x2F;github.com&#x2F;64kramsystem&#x2F;personal_notes&#x2F;tree&#x2F;master&#x2F;topics" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;64kramsystem&#x2F;personal_notes&#x2F;tree&#x2F;master&#x2F;t...</a>
l0b0将近 3 年前
Does my .bash_history[1] qualify?<p>[1] <a href="https:&#x2F;&#x2F;gitlab.com&#x2F;victor-engmark&#x2F;tilde&#x2F;-&#x2F;blob&#x2F;master&#x2F;.bash_history" rel="nofollow">https:&#x2F;&#x2F;gitlab.com&#x2F;victor-engmark&#x2F;tilde&#x2F;-&#x2F;blob&#x2F;master&#x2F;.bash_...</a>
ansible将近 3 年前
I use find and grep a lot in code repos, so I came up with this bash function:<p><pre><code> alias filter_repos_z=&quot;grep -ZzEv &#x27;&#x2F;tags|&#x2F;\.hg&#x2F;|&#x2F;\.svn&#x2F;|&#x2F;\.git&#x2F;|&#x2F;\.repo&#x2F;|\.o$|\.o\.cmd$|\.depend|\.map$|\.dep$|\.js$|\.html$&#x27;&quot; function findxgrep() { find . -type f -print0 | filter_repos_z | xargs -0 grep --color=auto &quot;${@}&quot; | grep -v &quot;^Binary file&quot; | sed &#x27;s&#x2F;^\.\&#x2F;&#x2F;&#x2F;&#x27; | less -F } </code></pre> The &quot;${@}&quot; is the critical bit that allows me to pass arguments like -i to grep. The grep, find and xargs commands all support using a NULL as a file separator instead of whitespace.
评论 #32471048 未加载
adityaathalye将近 3 年前
Favourite topic!<p>My &quot;Bash Toolkit&quot;: <a href="https:&#x2F;&#x2F;github.com&#x2F;adityaathalye&#x2F;bash-toolkit" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;adityaathalye&#x2F;bash-toolkit</a><p>My (yak-shaving-in-progress :) <i>&quot;little hot-reloadin&#x27; static shite generator from shell&quot;</i>: <a href="https:&#x2F;&#x2F;github.com&#x2F;adityaathalye&#x2F;shite" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;adityaathalye&#x2F;shite</a><p>A subtle-ish aspect is, I like to write Functional Programming style Bash. I&#x27;ve been blogging about it here: <a href="https:&#x2F;&#x2F;www.evalapply.org&#x2F;tags&#x2F;bash&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.evalapply.org&#x2F;tags&#x2F;bash&#x2F;</a>
olifante将近 3 年前
My favorite utility is a shell function for quickly attaching to an existing screen session after connecting via ssh (or creating a new one if none exists). It&#x27;s pretty handy for treating a single ssh connection to a server as if it was a long-lived multi-tab terminal:<p><pre><code> sshcreen () { ssh -t &quot;$@&quot; screen -xRR } </code></pre> Works with bash and zsh. Usage is pretty simple:<p><pre><code> $ sshcreen user@example.com </code></pre> Or for local Docker instances mapped to port 2222:<p><pre><code> $ sshcreen root@localhost -p 2222 </code></pre> Detach the session with CTRL-A + D, reattach by rerunning the sshcreen command you previously used.
hk1337将近 3 年前
This was handy before oh-my-zsh but omz has functionality for this now that it&#x27;s no longer necessary.<p><pre><code> pman() { man -t &quot;${1}&quot; | open -f -a &#x2F;System&#x2F;Applications&#x2F;Preview.app } </code></pre> I like using this in conjunction with pbcopy to quickly generate a random password at given length<p><pre><code> pwgen() { length=${1:-64} charlist=&#x27;0-9a-zA-Z~!@#$%^&amp;*()_+-=:&quot;;&lt;&gt;?,.&#x2F;&#x27; echo `cat &#x2F;dev&#x2F;random | tr -dc $charlist | head -c$length` }</code></pre>
评论 #32471134 未加载
评论 #32471126 未加载
monkin将近 3 年前
I use my system setup script: <a href="https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;binfiles&#x2F;blob&#x2F;master&#x2F;bt" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;binfiles&#x2F;blob&#x2F;master&#x2F;bt</a>. It helps me a lot with setting up new VPS when I need or with daily tasks. While using macOS, I also had this as helpers: <a href="https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;binfiles&#x2F;blob&#x2F;master&#x2F;.archive&#x2F;setup-brew" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;binfiles&#x2F;blob&#x2F;master&#x2F;.archive&#x2F;setup-...</a>, to set up homebrew. And, <a href="https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;binfiles&#x2F;blob&#x2F;master&#x2F;.archive&#x2F;setup-options-macos" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;binfiles&#x2F;blob&#x2F;master&#x2F;.archive&#x2F;setup-...</a>, for a bunch of options as many of build from source works fine in both systems. In .archive folder there’s a lot of other scripts that I used, but tried to incorporate them in bootstrap script.<p>It also uses my <a href="https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;dotfiles" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;dotfiles</a>, <a href="https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;vimfiles" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;vimfiles</a> and <a href="https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;zshfiles" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pcho&#x2F;zshfiles</a>
daneel_w将近 3 年前
<p><pre><code> alias makepw=&#x27;cat &#x2F;dev&#x2F;urandom | LC_ALL=C tr -cd A-Za-z0-9,_- | head -c 25; echo&#x27; </code></pre> Any proper password manager will of course be able to supplant tricks like these.
评论 #32468645 未加载
jader201将近 3 年前
Mint recently updated the API they use behind the scenes, and it broke the preexisting scripts others had written for importing transactions from a CSV (when you link a new bank, it only goes up to the past 90 days).<p>With my son having opened an account over a year ago, but we didn’t sign up for Mint until this weekend, I ended up writing a new import script for the updated API:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;jeradrose&#x2F;mint-simple-import" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jeradrose&#x2F;mint-simple-import</a>
jkern将近 3 年前
I&#x27;m not sure bashrc tweaks completely qualify but considering it involves probably the most convoluted shell script I&#x27;ve ever had to come up with I&#x27;ll plug <a href="https:&#x2F;&#x2F;github.com&#x2F;jkern888&#x2F;bash-dir-collapse" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jkern888&#x2F;bash-dir-collapse</a>. I like having the current directory in my prompt but got annoyed at how long it could get so made this to shrink the overall length without completely sacrificing the full path
jjice将近 3 年前
I&#x27;m looking in my `~&#x2F;bin` folder on my work machine right now. I have a good few that are very specific to my work.<p>- Scripts to test our rate limiting for both authenticated and unauthenticated users (was handy)<p>- API routes changed in a given PR (set of commits since the last interaction with master in reality)<p>- ssl-expiration-date - Checks the expiration date of a site&#x27;s certificate<p><pre><code> domain=&quot;$1&quot; echo &quot;Checking the SSL certificate expiration date for: $domain&quot; curl -vI &quot;$domain&quot; 2&gt;&amp;1 | grep -o &#x27;expire date: .*$&#x27; </code></pre> - test-tls-version - Checks if a website supports a given version of TLS<p><pre><code> domain=&quot;$1&quot; curl_options=( &quot;--tlsv${2}&quot; --tls-max &quot;$2&quot; ) curl &quot;${curl_options[@]}&quot; -vI &quot;$domain&quot; 2&gt;&amp;1 </code></pre> There are also some miscellaneous PHP scripts lying around for template related stuff. PHP makes a create templating language when you need some basic programmatic additions to your output text.<p>Everything is too coupled to my work to be useful to others, and most of the automation scripts I&#x27;ve written for work are run as cron jobs now and send out emails to the appropriate emails. Most of these are written in PHP (we&#x27;re a PHP shop).
bbkane将近 3 年前
Here&#x27;s a small script I use often to tag commits with Git.<p>It shows the current status, lists out the most recent tags, prompts for a new tag and message, and finally pushes.<p>Everything is colorized so it&#x27;s easy to read and I use it quite often for Golang projects.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;bbkane&#x2F;dotfiles&#x2F;blob&#x2F;e30c12c11a61ccc758f7894c0d5b962af3176ac9&#x2F;bin_common&#x2F;bin_common&#x2F;git-tagit" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bbkane&#x2F;dotfiles&#x2F;blob&#x2F;e30c12c11a61ccc758f7...</a>
pveierland将近 3 年前
I use a script called `shell-safe-rm` [1], aliased as `rm` in interactive shells, such that I don&#x27;t normally use `rm` directly. Instead of directly removing files, they are placed in the trash folder so they can be recovered if they were mistakenly deleted. Highly recommend using a script&#x2F;program like this to help prevent accidental data loss.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;kaelzhang&#x2F;shell-safe-rm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kaelzhang&#x2F;shell-safe-rm</a>
tls-kn将近 3 年前
Script I quickly wrote that automatically compiles my tex files on change, and reloads my pdf viewer (mupdf in this particular case). This was written for OpenBSD (TeXstudio wasn&#x27;t available, and I ended up liking this editor+mupdf approach even more), so I don&#x27;t know if it perfectly translates to other OSs.<p><pre><code> #!&#x2F;bin&#x2F;sh pdf_viewer=&quot;mupdf&quot;; latex_cmd=&quot;pdflatex -interaction=nonstopmode&quot; if [[ $# -eq 0 ]]; then print &quot;No arguments: filename required&quot; exit fi filename=$1; pdfname=${filename%%.*}.pdf # inital compilation to make sure a pdf file exists ${latex_cmd} ${filename}; ${pdf_viewer} ${pdfname} &amp; # get pid of the pdf viewer pdf_viewer_pid=$!; while true; do # as long as the pdf viewer is open, continue operation, if it gets closed, # end script if kill -0 &quot;${pdf_viewer_pid}&quot; 2&gt;&#x2F;dev&#x2F;null; then if [[ ${filename} -nt ${pdfname} ]]; then ${latex_cmd} ${filename}; # reload pdf file, only works with mupdf kill -HUP ${pdf_viewer_pid}; touch $pdfname fi sleep 1; else exit 0; fi done;</code></pre>
mstudio将近 3 年前
I sometimes leave a process running on a port for webdev and then try to open a new one resulting in the error, &quot;Error: listen EADDRINUSE 0.0.0.0:NNN&quot;, e.g. 0.0.0.0:443.<p>There are many ways to search for the process, but here&#x27;s what I use:<p><pre><code> lsof -iTCP -sTCP:LISTEN -P | grep [PORT NUMBER] </code></pre> Look for port num and kill the process with:<p><pre><code> kill -9 [PID OF PROCESS YOU WANT TO KILL] </code></pre> <i>Note</i> if running as root user, you will need to prepend the above commands with sudo
jmillikin将近 3 年前
I often have a need to serve a local directory via HTTP. In the old days the built-in Python webserver was enough, but at some point browsers became more aggressive about concurrent connections and the single-threaded `python -m SimpleHTTPServer` would just get stuck if it received two requests at once.<p>As a workaround, I wrote a small wrapper script that would enable multi-threading for SimpleHTTPServer.<p>~&#x2F;bin&#x2F;http-cwd , Python 2 version (original):<p><pre><code> #!&#x2F;usr&#x2F;bin&#x2F;python import argparse import BaseHTTPServer import SimpleHTTPServer import SocketServer import sys class ThreadedHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): pass def main(argv): parser = argparse.ArgumentParser() parser.add_argument( &quot;--port&quot;, type = int, nargs = &quot;?&quot;, action = &quot;store&quot;, default = 8000, help = &quot;Specify alternate port [default: 8000]&quot;, ) parser.add_argument( &quot;--iface&quot;, type = str, nargs = &quot;?&quot;, action = &quot;store&quot;, default = &quot;127.0.0.1&quot;, help = &quot;Specify iface [default: 127.0.0.1]&quot;, ) args = parser.parse_args(argv[1:]) server_address = (args.iface, args.port) srv = ThreadedHTTPServer(server_address, SimpleHTTPServer.SimpleHTTPRequestHandler) sa = srv.socket.getsockname() print &quot;Serving http:&#x2F;&#x2F;%s:%r ...&quot; % (sa[0], sa[1]) srv.serve_forever() if __name__ == &quot;__main__&quot;: sys.exit(main(sys.argv)) </code></pre> Python 3 version (necessary for platforms that have dropped Python 2, such as macOS):<p><pre><code> #!&#x2F;usr&#x2F;bin&#x2F;python3 import argparse import http.server import socketserver import sys class ThreadedHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer): pass def main(argv): parser = argparse.ArgumentParser() parser.add_argument( &quot;--port&quot;, type = int, nargs = &quot;?&quot;, action = &quot;store&quot;, default = 8000, help = &quot;Specify alternate port [default: 8000]&quot;, ) parser.add_argument( &quot;--iface&quot;, type = str, nargs = &quot;?&quot;, action = &quot;store&quot;, default = &quot;127.0.0.1&quot;, help = &quot;Specify iface [default: 127.0.0.1]&quot;, ) args = parser.parse_args(argv[1:]) server_address = (args.iface, args.port) srv = ThreadedHTTPServer(server_address, http.server.SimpleHTTPRequestHandler) sa = srv.socket.getsockname() print(&quot;Serving http:&#x2F;&#x2F;%s:%r ...&quot; % (sa[0], sa[1])) srv.serve_forever() if __name__ == &quot;__main__&quot;: sys.exit(main(sys.argv))</code></pre>
评论 #32472572 未加载
jasonariddle将近 3 年前
Yup, here are mine.<p><pre><code> # Search all directories for this directory name. dname() { [ $# -eq 0 ] &amp;&amp; echo &quot;$0 &#x27;dir_name&#x27;&quot; &amp;&amp; return 1 fd --hidden --follow --exclude .git --type directory &quot;$*&quot; } # Search all files for this filename. fname() { [ $# -eq 0 ] &amp;&amp; echo &quot;$0 &#x27;file_name&#x27;&quot; &amp;&amp; return 1 fd --hidden --follow --exclude .git --type file &quot;$*&quot; } # Find and replace with a pattern and replacement sub() { [ $# -ne 2 ] &amp;&amp; echo &quot;$0 &#x27;pattern&#x27; &#x27;replacement&#x27;&quot; &amp;&amp; return 1 pattern=&quot;$1&quot; replace=&quot;$2&quot; command rg -0 --files-with-matches &quot;$pattern&quot; --hidden --glob &#x27;!.git&#x27; | xargs -0 perl -pi -e &quot;s|$pattern|$replace|g&quot; } # Uses z and fzf, if there&#x27;s a match then jump to it. If not, bring up a list via fzf to fuzzy search. unalias z 2&gt; &#x2F;dev&#x2F;null z() { [ $# -gt 0 ] &amp;&amp; _z &quot;$*&quot; &amp;&amp; return cd &quot;$(_z -l 2&gt;&amp;1 | sed &#x27;s&#x2F;^[0-9,.]* *&#x2F;&#x2F;&#x27; | fzf)&quot; }</code></pre>
PeterWhittaker将近 3 年前
Shorthand to find all files matching a pattern (with optional additional arguments, e.g., -delete, -ls, -exec ..., etc.<p><pre><code> fndi () { tgt=&quot;${1}&quot;; shift; echo find . -iname \*&quot;${tgt}&quot;\* &quot;${@}&quot;; find . -iname \*&quot;${tgt}&quot;\* &quot;${@}&quot; 2&gt; &#x2F;dev&#x2F;null; [[ -z $tgt ]] &amp;&amp; { echo; echo &quot;No target was specified, did the results surprise?&quot; } } </code></pre> Shorthand to find all files containing a pattern:<p><pre><code> fndg () { binOpt=&quot;-I&quot;; wordOpt=&quot;&quot;; caseOpt=&quot;-i&quot;; while true; do if [[ -z $1 || $1 =~ ^[^-+] ]]; then break; fi; case $1 in +i) caseOpt=&quot;&quot; ;; -B) binOpt=&quot;&quot; ;; -w) wordOpt=&quot;-w&quot; ;; *) echo &quot;Unrecognized option &#x27;${1}&#x27;, cannot proceed.&quot;; return 1 ;; esac; shift; done; if [[ -z $2 ]]; then startIn=.; else startIn=&#x27;&#x27;; while [[ ! -z $2 ]]; do startIn+=&quot;$1 &quot;; shift; done; fi; [[ -z $1 ]] &amp;&amp; { echo &quot;No target specified, cannot proceed.&quot;; return }; tgt=$1; echo find ${startIn} -type f -exec grep $binOpt $wordOpt $caseOpt -H &quot;${tgt}&quot; {} \;; find ${startIn} -type f -exec grep $binOpt $wordOpt $caseOpt -H &quot;${tgt}&quot; {} \; 2&gt; &#x2F;dev&#x2F;null }</code></pre>
Linux-Fan将近 3 年前
My most-used self-written script is probably ``syssheet` -- this script displays information about the running system in terms of load (RAM usage, disk usage, load avg, users) and Hardware (CPU model, Network Interfaces...). It is like a crossover between top and inxi. I use it to clearly distinguish what kind of system I am logging into and deploy it to all of my systems: <a href="https:&#x2F;&#x2F;masysma.lima-city.de&#x2F;11&#x2F;syssheet.xhtml" rel="nofollow">https:&#x2F;&#x2F;masysma.lima-city.de&#x2F;11&#x2F;syssheet.xhtml</a><p>There is also a collection of more &quot;obscure&quot; scripts in my shellscripts repository documented here: <a href="https:&#x2F;&#x2F;masysma.lima-city.de&#x2F;32&#x2F;shellscripts.xhtml" rel="nofollow">https:&#x2F;&#x2F;masysma.lima-city.de&#x2F;32&#x2F;shellscripts.xhtml</a>.<p>Another (probably niché) topic is my handling of scanned documents which arrive as PDFs from the scanner and that I want to number according to the stamped number on the document and convert to png at reduced color space: <a href="https:&#x2F;&#x2F;masysma.lima-city.de&#x2F;32&#x2F;scanning.xhtml" rel="nofollow">https:&#x2F;&#x2F;masysma.lima-city.de&#x2F;32&#x2F;scanning.xhtml</a>
zem将近 3 年前
not mine (i stole it from someone else) but very useful bash prompt_func to store your entire bash history forever:<p>8&lt;-----------------------------<p><pre><code> function prompt_func { CMDNUM=`history 1 | awk &#x27;{print $1}&#x27;` LAST_CMD=`history 1 | cut -f 3- -d &#x27; &#x27;` if [ x$LAST_CMDNUM = xwho_knows ]; then LAST_CMDNUM=$CMDNUM fi if [ x$CMDNUM != x$LAST_CMDNUM ]; then FULL_CMD_LOG=&quot;$HOME&#x2F;full-history&#x2F;$(date &quot;+%Y-%m-%d&quot;).log&quot; echo &quot;$(date &#x27;+%H:%M:%S&#x27;) `munge_pwd` $LAST_CMD&quot; &gt;&gt; $FULL_CMD_LOG LAST_CMDNUM=$CMDNUM fi } export PROMPT_COMMAND=prompt_func export LAST_CMDNUM=who_knows function fh() { grep -r --color=NEVER ${*} ~&#x2F;full-history | sed &#x27;s&#x2F;[^ ]* &#x2F;&#x2F;&#x27; | sed &#x27;s&#x2F; \[[^]]\*\]&#x2F;$&#x2F;&#x27; } </code></pre> 8&lt;-----------------------------<p>`munge_pwd` is another script that does various substitutions on the prompt (specific to how my work directories are laid out) but mostly you can just substitute `pwd` if you don&#x27;t care about deduplicating stuff like multiple checkouts of the same project.
评论 #32477466 未加载
djsamseng将近 3 年前
Recursive grep: For every time you know you’ve written that code before but can’t remember the exact syntax. Filters out known build directories that would otherwise make it slow (moddify this to your personal use case).<p><a href="https:&#x2F;&#x2F;github.com&#x2F;djsamseng&#x2F;cheat_sheet&#x2F;blob&#x2F;main&#x2F;grep_for_text.sh" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;djsamseng&#x2F;cheat_sheet&#x2F;blob&#x2F;main&#x2F;grep_for_...</a><p>#!&#x2F;bin&#x2F;bash<p>if [ $# -eq 0 ] then echo &quot;Usage: .&#x2F;grep_for_text.sh \&quot;text to find\&quot; &#x2F;path&#x2F;to&#x2F;folder --include=*.{cpp,h}&quot; exit fi<p>text=$1 location=$2<p># Remove $1 and $2 to pass remaining arguments as $@ shift shift<p>result=$(grep -Ril &quot;$text&quot; &quot;$location&quot; \ $@ \ --exclude-dir=node_modules --exclude-dir=build --exclude-dir=env --exclude-dir=lib \ --exclude-dir=.data --exclude-dir=.git --exclude-dir=data --exclude-dir=include \ --exclude-dir=__pycache__ --exclude-dir=.cache --exclude-dir=docs \ --exclude-dir=share --exclude-dir=odas --exclude-dir=dependencies \ --exclude-dir=assets)<p>echo &quot;$result&quot;
评论 #32468608 未加载
评论 #32469235 未加载
评论 #32468801 未加载
mxvzr将近 3 年前
<p><pre><code> json2yaml() { python3 -c &quot;import json,sys,yaml; print(yaml.dump(json.load(sys.stdin)))&quot; } export -f json2yaml yaml2json() { python3 -c &quot;import json,sys,yaml; json.dump(yaml.safe_load(sys.stdin), sys.stdout, default=str)&quot; } export -f yaml2json httping() { while true; do curl $@ -so &#x2F;dev&#x2F;null \ -w &quot;connected to %{remote_ip}:%{remote_port}, code=%{response_code} time=%{time_total}s\n&quot; \ || return $? sleep 1 done } [[ ! $(&gt;&amp;&#x2F;dev&#x2F;null type httping) ]] &amp;&amp; export -f httping redis-cli() { REDIS_HOST=&quot;${1:-127.0.0.1}&quot; REDIS_PORT=&quot;${2:-6379}&quot; rlwrap -S &quot;${REDIS_HOST}:${REDIS_PORT}&gt; &quot; socat tcp:${REDIS_HOST}:${REDIS_PORT} STDIO } [[ ! $(&gt;&amp;&#x2F;dev&#x2F;null type redis-cli) ]] &amp;&amp; export -f redis-cli</code></pre>
stuporglue将近 3 年前
Does a PostgreSQL plpgsql function count as a script?<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;stuporglue&#x2F;83714cdfa0e4b4401cb6" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;stuporglue&#x2F;83714cdfa0e4b4401cb6</a><p>It&#x27;s one of my favorites because it&#x27;s pretty simple, and I wrote it when a lot of things were finally coming together for me (including GIS concepts, plpgsql programming, and a project I was working on at the time).<p>This is code which takes either two foci points and a distance, or two foci, a distance and the number of pointers per quadrant and generates a polygon representing an ellipse. Nothing fancy, but it made me happy when I finally got it working.<p>The use case was to calculate a naive estimate of how far someone could have ridden on a bike share bike. I had the locations they checked out the bike, and where they returned it, and the time they were gone. By assuming some average speed, I could make an ellipse where everywhere within the ellipse could have been reached during the bike rental.
digitalsushi将近 3 年前
I have a shell function exported called &quot;cheat&quot;. It looks for a plain text file in a specific location named after the one argument to cheat() and it just prints the file out. I think it might glob and print multiples out.<p>And then I have different dotfile repos. I have a base one that I keep so clean I could get a job at Disney with it. That&#x27;s where most of my scripts live. And then I have locale ones, like -home, -&lt;employername&gt;. Those have overlays so that I can have contextual extensions, such as a cheat database with work stuff. Also, I can keep that dotfile-employername hosted at my employer so that I&#x27;m not &quot;crossing the streams&quot;. I don&#x27;t even have to link them, they just autoload based on their location and name.<p>I don&#x27;t have to hop systems too much, so grabbing fresh tooling is a twice a year problem. I&#x27;m a cli-as-ide dinosaur so I just hide all my seldom-used scripts under a double underscore prefix. __init_tooling will update vim and give me the 8 or 9 plugins I have grown dependent upon, give me a ruby and python environment, etc.<p>I have a function called &quot;add_word&quot;. Every time I see a word I dont know, I learn it, and then I run &quot;add_word &lt;new word&gt; &lt;definition&gt;&quot;. It creates a new file called &lt;new word&gt; with the definition and commits it to a git repo hidden away. Every couple years I&#x27;ll work through the list and see which I remember. I have about a 30% success rate adopting new words, which again, dinosaur here, so, I&#x27;ll take whatever I can get.<p>The dirtiest thing I have is a cheap vault that uses vim and shell automation. I have a grammar for descripting secrets, and I can pass a passphrase through automation to get secrets out. I&#x27;m sure it&#x27;s 100% hackable. I know the first rule of security software is &quot;dont ever try to make your own&quot;. So I don&#x27;t put anything too good in there.
评论 #32469811 未加载
alexpotato将近 3 年前
I wasn&#x27;t the author but if I had to pick one set of scripts that have lowered my anxiety the most it&#x27;s this: <a href="http:&#x2F;&#x2F;www.mikerubel.org&#x2F;computers&#x2F;rsync_snapshots&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.mikerubel.org&#x2F;computers&#x2F;rsync_snapshots&#x2F;</a><p>Long story short: you can use hard links + rsync to create delta snapshots of a directory tree. I use it to create a back up of my important directory trees.<p>Funny story about this: I had really old HP &quot;Lance Armstrong&quot; branded laptop that I used for years. The above above script was on it and was rsyincing to separate machine so it was fully backed up. Because of that, I was actually hoping for the laptop to die so I could get a new one (frugalness kicking in strong here).<p>My girlfriend at the time was using it and said &quot;Oh, should I not eat or drink over your laptop?&quot; and I responded: &quot;No, please do! If you break it that means I can allow myself to order a new one.&quot;
zzo38computer将近 3 年前
Access Firefox bookmarks from command-line:<p><pre><code> f0() { echo &#x27;select moz_bookmarks.title || &#x27;&quot;&#x27;&quot;&#x27; = &#x27;&quot;&#x27;&quot;&#x27; || url from moz_places, moz_bookmarks on moz_places.id = moz_bookmarks.fk where parent = 2;&#x27; | sqlite3 &#x2F;home&#x2F;user&#x2F;.mozilla&#x2F;firefox&#x2F;twht79zd.default&#x2F;places.sqlite } f1() { firefox `echo &#x27;select url from moz_places, moz_bookmarks on moz_places.id = moz_bookmarks.fk where moz_bookmarks.title = &#x27;&quot;&#x27;$1&#x27;&quot;&#x27;;&#x27; | sqlite3 &#x2F;home&#x2F;user&#x2F;.mozilla&#x2F;firefox&#x2F;twht79zd.default&#x2F;places.sqlite` } f$# $1 </code></pre> Execute PostScript programs alone with command-line arguments:<p><pre><code> exec gs -P -dBATCH -dNODISPLAY -dNOEPS -dNOPAUSE -dNOSAFER -q -- &quot;$@&quot; </code></pre> Tell the IP address:<p><pre><code> curl -s &#x27;http:&#x2F;&#x2F;icanhazip.com&#x2F;&#x27; | cat -v</code></pre>
kakulukia超过 2 年前
If you are polite, it works:<p>alias please=&#x27;sudo zsh -c &quot;$(fc -ln -1)&quot;&#x27; # rerun the last command with sudo (because it failed )<p>Easier PATH management:<p># nicer path configuration and lookup function path { if [[ $# -eq 0 ]]; then echo -e ${PATH&#x2F;&#x2F;:&#x2F;\\n} | sort elif [[ &quot;$1&quot; == &quot;--save&quot; ]]; then path $2 &amp;&amp; echo &quot;\npath $2&quot; &gt;&gt; $HOME&#x2F;.profile else if [[ -d &quot;$1&quot; ]] ; then if [[ -z &quot;$PATH&quot; ]] ; then export PATH=$1 else export PATH=$1:$PATH fi else echo &quot;$1 does not exist :(&quot; return 1 fi fi }
hcrean将近 3 年前
python3 -c &quot;import pyotp ; print(pyotp.TOTP(&#x27;&lt;MY_TOTP_2FA_SECRET&gt;&#x27;.lower()).now())&quot;<p>This is a bash one-liner that takes the place of an RSA&#x2F;2FA token&#x2F;AuthyApp
评论 #32477388 未加载
jamesralph8555将近 3 年前
Wrote this simple one to create gzipped tar backups and send them over ssh. A lot faster than rsync if you just need to back up a whole folder on a schedule. It requires pigz, which is a parallel gzip implementation.<p>Variables: $HOSTNAME - the computer hostname $TOBACKUPDIR - the local directory you want backed up $N_CORES - the number of cores you want to use for compression $REMOTEUSER - the ssh user login on the remote server $REMOTEHOST - the remote server&#x27;s IP $BACKUPDIR - where you want the file to be backed up to<p>#!&#x2F;bin&#x2F;bash<p>bfile=`date +%F`.$HOSTNAME.tar.gz<p><pre><code> &#x2F;usr&#x2F;bin&#x2F;tar cvpf - \ # You can exclude local directories here with # --exclude=&quot;dir&quot; \ $TOBACKUPDIR | pigz -p $N_CORES | \ ssh $REMOTEUSER@$REMOTEHOST &quot;cat - &gt; &#x2F;$BACKUPDIR&#x2F;$bfile&quot;</code></pre>
alsetmusic将近 3 年前
This is not mine. I can’t remember where I found it. Apologies for no attribution (Mac):<p>#!&#x2F;usr&#x2F;bin&#x2F;env bash<p>function cdf() { #: Change working directory to the top-most Finder window location cd &quot;$(osascript -e &#x27;tell app &quot;Finder&quot; to POSIX path of (insertion location as alias)&#x27;)&quot;; }
评论 #32470557 未加载
评论 #32470379 未加载
mickeyp将近 3 年前
A bash script + a little elisp magic that leverages Emacs for fuzzy finding on the command line instead of fzf:<p><a href="https:&#x2F;&#x2F;www.masteringemacs.org&#x2F;article&#x2F;fuzzy-finding-emacs-instead-of-fzf" rel="nofollow">https:&#x2F;&#x2F;www.masteringemacs.org&#x2F;article&#x2F;fuzzy-finding-emacs-i...</a>
tengwar2将近 3 年前
This is embarrassingly simple, but useful.<p><pre><code> manps() { if [ -z &quot;$1&quot; ]; then echo usage: $FUNCNAME topic echo This will open a PostScript formatted version of the man page for \&#x27;topic\&#x27;. else man -t $1 | open -f -a &#x2F;Applications&#x2F;Preview.app fi } </code></pre> This is for MacOS. All it does is display a `man` entry as properly formatted Postscript. If you were around in the 80&#x27;s when we had ring-bound paper manuals, you may remember how much easier they were to read as compared with fixed-pitch terminal rendering of the same page.<p>Sorry, no Linux version as I rarely have a graphical desktop open on Linux. It should be easy to rig something up with Ghostscript or similar.
评论 #32484976 未加载
ransom1538将近 3 年前
Let&#x27;s say you have a cronjob YOUR_CRONJOB.php that is slow that uses a query to get the data it needs to iterate over. Change your sql where to have MOD(id, total_threads) = MOD. Toss this into jenkins and you are set.<p>This will fork it and wait until it ends.<p>#!&#x2F;bin&#x2F;bash<p>TOTAL=`ps aux | grep YOUR_CRONJOB.php | grep -v grep | wc -l`<p>echo &quot;TOTAL PROCESSES ALREADY RUNNING :&quot;$TOTAL<p>MAX_THREADS=20<p>TOTAL_MODS=&quot;$(($MAX_THREADS-1))&quot;<p>echo &quot;TOTAL MODS: &quot;$TOTAL_MODS<p>if [ $TOTAL -eq 0 ]<p>then<p><pre><code> echo &quot;RUNNING...&quot; for i in $(seq 0 $TOTAL_MODS) do echo &quot;Starting thread $i&quot; timeout 10000 php YOUR_CRONJOB.php $i $MAX_THREADS &amp; pids[${i}]=$! done echo &quot;FINISHED FORKING&quot; </code></pre> else<p><pre><code> echo &quot;NOT RUNNING....&quot; </code></pre> fi<p>for pid in ${pids[*]}; do<p><pre><code> wait $pid </code></pre> done<p>echo &quot;OK FINISHED&quot;
yabones将近 3 年前
Few years ago, I needed a quick way to create Qemu VM&#x27;s locally for testing some weird software configurations. So I made a script to pull Ubuntu cloud images and clone them into qcow2 disks, then create and register libvirt virtual machines. Part of the &quot;magic&quot; was creating a cloud-config ISO image that would be mounted to pre-seed the VM on first launch. It also pushed my ssh key into the VM so I wouldn&#x27;t need to use passwords. Janky, but worked well for what I needed.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;noahbailey&#x2F;kvmgr&#x2F;blob&#x2F;master&#x2F;kvmgr.sh" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;noahbailey&#x2F;kvmgr&#x2F;blob&#x2F;master&#x2F;kvmgr.sh</a>
axelf4将近 3 年前
Here is my script gfm-preview [1], which I think is pretty cool since it implements a HTTP server in 50 lines of shell script (ab-)use with netcat. What is does is it starts a HTTP server that serves a rendered preview of a Markdown document using GitHub&#x27;s API for rendering GitHub Flavoured Markdown. The page will automatically update when the document changes using fswatch and HTTP long polling!<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;axelf4&#x2F;nixos-config&#x2F;blob&#x2F;e90e897243e1d13579ae8300ae51d7b628b0a87a&#x2F;packages&#x2F;gfm-preview&#x2F;gfm-preview" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;axelf4&#x2F;nixos-config&#x2F;blob&#x2F;e90e897243e1d135...</a>
cednore将近 3 年前
I use these aliases to deal with QR codes.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;cednore&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;.functions#L1-L2" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cednore&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;.functions#L...</a> <a href="https:&#x2F;&#x2F;github.com&#x2F;cednore&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;.aliases#L46-L50" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cednore&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;.aliases#L46...</a>
评论 #32522370 未加载
RhysU将近 3 年前
A shebang-friendly script for &quot;interpreting&quot; single C99, C11, and C++ files, including rcfile support: <a href="https:&#x2F;&#x2F;github.com&#x2F;RhysU&#x2F;c99sh&#x2F;blob&#x2F;master&#x2F;c99sh" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;RhysU&#x2F;c99sh&#x2F;blob&#x2F;master&#x2F;c99sh</a><p>Use gnuplot to plot one or more files directly from the command line: <a href="https:&#x2F;&#x2F;github.com&#x2F;RhysU&#x2F;gplot&#x2F;blob&#x2F;master&#x2F;gplot" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;RhysU&#x2F;gplot&#x2F;blob&#x2F;master&#x2F;gplot</a>
vbezhenar将近 3 年前
Some zsh functions I can&#x27;t live without<p><pre><code> mkcd() { mkdir -p &quot;$1&quot; &amp;&amp; cd &quot;$1&quot; } mkcdtmp() { mkcd ~&#x2F;tmp&#x2F;$(date &quot;+%y%m%d&quot;) }</code></pre>
lukaszkups将近 3 年前
Oh gosh, that made me soo nostalgic - I did such mono .sh file to boost my system setup couple years ago as elementaryOS at the time was not supporting updates and I had to do a clean install when new release was published: <a href="https:&#x2F;&#x2F;github.com&#x2F;mrmnmly&#x2F;linux-installation-script&#x2F;blob&#x2F;master&#x2F;install.sh" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mrmnmly&#x2F;linux-installation-script&#x2F;blob&#x2F;ma...</a><p>When I read it today I miss those soo oversimplified solutions to do stuff :&#x27;-)
burntsushi将近 3 年前
My dotfiles: <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles</a><p>Here are some selected scripts folks might find interesting.<p>Here&#x27;s my backup script that I use to encrypt my data at rest before shipping it off to s3. Runs every night and is idempotent. I use s3 lifecycle rules to keep data around for 6 months after it&#x27;s deleted. That way, if my script goofs, I can recover: <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae7f0a7cea1a641459e25e5d07&#x2F;bin&#x2F;backup" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae...</a><p>I have so many machines running Archlinux that I wrote my own little helper for installing Arch that configures the machine in the way I expect: <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae7f0a7cea1a641459e25e5d07&#x2F;bin&#x2F;arch-install" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae...</a><p>A tiny little script to recover the git commit message you spent 10 minutes writing, but &quot;lost&quot; because something caused the actual commit to fail (like a gpg error): <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae7f0a7cea1a641459e25e5d07&#x2F;bin&#x2F;git-view-prior-commit-message" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae...</a><p>A script that produces a GitHub permalink from just a file path and some optional file numbers. Pass --clip to put it on your clipboard: <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae7f0a7cea1a641459e25e5d07&#x2F;bin&#x2F;github-link" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae...</a> --- I use it with this vimscript function to quickly generate permalinks from my editor: <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae7f0a7cea1a641459e25e5d07&#x2F;.config&#x2F;nvim&#x2F;include&#x2F;githublink.vim" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae...</a><p>A wrapper around &#x27;gh&#x27; (previously: &#x27;hub&#x27;) that lets you run &#x27;hub-rollup pr-number&#x27; and it will automatically rebase that PR into your current branch. This is useful for creating one big &quot;rollup&quot; branch of a bunch of PRs. It is idempotent. <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae7f0a7cea1a641459e25e5d07&#x2F;bin&#x2F;hub-rollup" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae...</a><p>Scale a video without having to memorize ffmpeg&#x27;s crazy CLI syntax: <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae7f0a7cea1a641459e25e5d07&#x2F;bin&#x2F;video-scale" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae...</a><p>Under X11, copy something to your clipboard using the best tool available: <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae7f0a7cea1a641459e25e5d07&#x2F;bin&#x2F;xcp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;dotfiles&#x2F;blob&#x2F;2f58eedf3b7f7dae...</a>
gitgud将近 3 年前
Here&#x27;s my dotfiles repository [1], which is used to sync my little scripts and config files between my different systems (Mac&#x2F;Linux). I first heard about it here [2].<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;benwinding&#x2F;dotfiles" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;benwinding&#x2F;dotfiles</a><p>[2] <a href="https:&#x2F;&#x2F;zachholman.com&#x2F;2010&#x2F;08&#x2F;dotfiles-are-meant-to-be-forked&#x2F;" rel="nofollow">https:&#x2F;&#x2F;zachholman.com&#x2F;2010&#x2F;08&#x2F;dotfiles-are-meant-to-be-fork...</a>
zwischenzug将近 3 年前
Not a script as such, but I did put this together, building on what someone else did:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ianmiell&#x2F;bash-template" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ianmiell&#x2F;bash-template</a><p>It&#x27;s a &#x27;cut and paste&#x27; starter for shell scripts that tries to be as robust as possible while not going crazy with the scaffolding. Useful for &quot;I want to quickly cut a script and put it into our source but don&#x27;t want it to look totally hacky&quot; situations.
评论 #32473440 未加载
sumosudo将近 3 年前
<p><pre><code> autoload -U add-zsh-hook add-zsh-hook chpwd source_env source_env() { if [[ -f .env &amp;&amp; -r .env ]]; then source .env fi }</code></pre>
评论 #32468900 未加载
lifefeed将近 3 年前
Small bash functions that&#x27;re useful for silly-ego-reasons.<p><pre><code> ## coding analysis function lines_coded { perl -ne&#x27;print unless &#x2F;^\s*$&#x2F; || &#x2F;^\s*(?:#|\&#x2F;\*|\*)&#x2F;&#x27; $* | wl } function lines_commented { perl -ne&#x27;print if &#x2F;^\s*(?:#|\&#x2F;\*|\*)&#x2F;&#x27; $* | wl } </code></pre> And wl is just a small alias (because I used it all the time):<p><pre><code> wl=&#x27;wc -l&#x27;</code></pre>
jamescampbell将近 3 年前
My Mac OS bootstrap script to setup any new Mac from scratch. It includes niceties like moving the default screenshots from the Desktop to a more sane location, setting full disk encryption, and setting up privoxy &amp; dnscrypt out if the box. <a href="https:&#x2F;&#x2F;github.com&#x2F;james-see&#x2F;fresh-mac" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;james-see&#x2F;fresh-mac</a>
altilunium将近 3 年前
With this i can produce beautifully typesetted latex PDF and publish a blogpost, right from my text editor.<p><a href="https:&#x2F;&#x2F;rtnf.prose.sh&#x2F;prose-sublime-text-integration" rel="nofollow">https:&#x2F;&#x2F;rtnf.prose.sh&#x2F;prose-sublime-text-integration</a><p><a href="https:&#x2F;&#x2F;rtnf.prose.sh&#x2F;pandoc-sublime-text-integration" rel="nofollow">https:&#x2F;&#x2F;rtnf.prose.sh&#x2F;pandoc-sublime-text-integration</a>
hnarayanan将近 3 年前
I use the following definition in my .profile to be able to replace foo with bar in all text files within a folder.<p><pre><code> replace() { grep -rl &quot;$1&quot; . | xargs gsed -i &quot;s&#x2F;$1&#x2F;$2&#x2F;g&quot; } </code></pre> Also, I run Spotify from the command line: <a href="https:&#x2F;&#x2F;github.com&#x2F;hnarayanan&#x2F;shpotify" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;hnarayanan&#x2F;shpotify</a>
评论 #32470559 未加载
Freaky将近 3 年前
borg-backup.sh, which runs my remote borg backups off a cronjob: <a href="https:&#x2F;&#x2F;github.com&#x2F;Freaky&#x2F;borg-backup.sh" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Freaky&#x2F;borg-backup.sh</a><p>zfsnapr, a ZFS recursive snapshot mounter - I run borg-backup.sh using this to make consistent backups: <a href="https:&#x2F;&#x2F;github.com&#x2F;Freaky&#x2F;zfsnapr" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Freaky&#x2F;zfsnapr</a><p>mkjail, an automatic minimal FreeBSD chroot environment builder: <a href="https:&#x2F;&#x2F;github.com&#x2F;Freaky&#x2F;mkjail" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Freaky&#x2F;mkjail</a><p>run-one, a clone of the Ubuntu scripts of the same name, which provides a slightly friendlier alternative to running commands with flock&#x2F;lockf: <a href="https:&#x2F;&#x2F;github.com&#x2F;Freaky&#x2F;run-one" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Freaky&#x2F;run-one</a><p>ioztat, a Python script that basically provides what zfs-iostat(8) would if it existed: <a href="https:&#x2F;&#x2F;github.com&#x2F;jimsalterjrs&#x2F;ioztat" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jimsalterjrs&#x2F;ioztat</a>
thedanbob将近 3 年前
Not sure whether to be proud or ashamed of this, but this script runs in a cron job to monitor my home server’s IPv4 and IPv6 addresses and update them everywhere (DNS, firewall, reverse proxies) if they change: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;thedanbob&#x2F;13f88ca8c21cb2ab7904ec5a6e9fff7e" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;thedanbob&#x2F;13f88ca8c21cb2ab7904ec5a6e...</a>
评论 #32468533 未加载
gengiskush将近 3 年前
<a href="https:&#x2F;&#x2F;bitbucket.org&#x2F;mieszkowski&#x2F;introspect&#x2F;src&#x2F;master&#x2F;" rel="nofollow">https:&#x2F;&#x2F;bitbucket.org&#x2F;mieszkowski&#x2F;introspect&#x2F;src&#x2F;master&#x2F;</a><p>I replaced Plone for my personal use with about 1000 lines of Python. A object oriented database. The interface is awkward but if you get past that the goal was to produce pictures of trees with graphviz.
mauli将近 3 年前
I started - but rarely update and kinda forgot pushing to github - some small scripts and knowledge snippets. One of them being a network&#x2F;ssh based distributed unseal mechanism (using shamir algorithm) to allow machines to boot and decrypt their OS partition.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;maulware&#x2F;maulstuff" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;maulware&#x2F;maulstuff</a>
PainfullyNormal将近 3 年前
I wrote a silly little script to play a random assortment of music.<p><pre><code> playMeSomeMusicMan() { rg --files -tmusic ~&#x2F;Music | shuf | mpv --playlist=- } </code></pre> I also got sick of waiting for Activity Monitor to boot to kill an errant process, so I wrote this one to fuzzy search and kill the selection.<p><pre><code> kp() { ps aux | fzy | awk &#x27;{ print $2 }&#x27; | xargs kill }</code></pre>
hyperman1将近 3 年前
themicrosoftchainsawmassacre.cmd<p><pre><code> TASKKILL &#x2F;IM outlook.exe TASKKILL &#x2F;IM teams.exe TASKKILL &#x2F;IM onedrive.exe timeout &#x2F;t 2 TASKKILL &#x2F;F &#x2F;IM outlook.exe TASKKILL &#x2F;F &#x2F;IM teams.exe TASKKILL &#x2F;F &#x2F;IM onedrive.exe TASKKILL &#x2F;F &#x2F;IM Microsoft.AAD.BrokerPlugin.exe timeout &#x2F;t 2 start outlook.exe start &quot;&quot; %LOCALAPPDATA%\Microsoft\Teams\Update.exe --processStart &quot;Teams.exe&quot; start &quot;&quot; &quot;C:\Program Files\Microsoft OneDrive\OneDrive.exe&quot; &#x2F;background </code></pre> There is a short period between network start and VPN start where all the microsoft thingies start and want me to login again. As their SMSes sometimes take hours to arrive, it is more easye to just kill and restart them, and let them reuse their existing login.<p>So I dropped the batch above on my desktop, and click it while the VPN is starting up. In the 4 seconds it takes to kill everything, the network works as it should.
fastily将近 3 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;fastily&#x2F;autobots" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fastily&#x2F;autobots</a>
RijilV将近 3 年前
I find this one handy:<p>#!&#x2F;bin&#x2F;bash echo |\ openssl s_client -connect ${1:?Usage: $0 HOSTNAME [PORT] [x509 OPTIONS]}:${2:-443} 2&gt;&amp;1 |\ sed -ne &#x27;&#x2F;-BEGIN CERTIFICATE-&#x2F;,&#x2F;-END CERTIFICATE-&#x2F;p&#x27; |\ openssl x509 ${3:--text} ${@:4} 2&gt;&#x2F;dev&#x2F;null |\ sed &#x27;&#x2F;-BEGIN CERTIFICATE-&#x2F;,&#x2F;-END CERTIFICATE-&#x2F;d&#x27;
efitz将近 3 年前
Here’s one I wrote recently to take a list of domains and enumerate subdomains using sublist3r. Mostly it wraps the latter tool and cleans up the output, but it also enriches the output with dig info.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ericfitz&#x2F;dominfo" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ericfitz&#x2F;dominfo</a><p>Dependencies: sublist3r (Python) pv (used for progress bars)
0xbadcafebee将近 3 年前
My junk drawer: <a href="https:&#x2F;&#x2F;github.com&#x2F;peterwwillis&#x2F;junkdrawer" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;peterwwillis&#x2F;junkdrawer</a><p>The junk I haven&#x27;t touched in 10 years: <a href="https:&#x2F;&#x2F;github.com&#x2F;psypete&#x2F;public-bin&#x2F;src" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;psypete&#x2F;public-bin&#x2F;src</a>
ilozinski将近 3 年前
I work on an m1 macbook and a lot of times using arm architecture breaks dependencies. I have two really basic functions in my .zshrc (should also work for bash):<p># M1 compatibility switches<p>arm() { arch -arm64 &quot;${@:-$SHELL}&quot; }<p>x86() { arch -x86_64 &quot;${@:-$SHELL}&quot; }<p>This with the addition of `$(uname -m)` in my $PROMPT, has saved me a lot of time by letting me switch between arm and x86_64 architecture.
klysm将近 3 年前
My philosophy is that if I need a script something is wrong. Unfortunately a lot of things are wrong so I have a lot of scripts
maybe_pablo将近 3 年前
A quick one to display the contents of my scripts:<p><pre><code> $ wat wat #!&#x2F;usr&#x2F;bin&#x2F;env bash cat `which $1`</code></pre>
评论 #32470328 未加载
MiddleEndian将近 3 年前
Photoshop Mask Placer: <a href="https:&#x2F;&#x2F;www.middleendian.com&#x2F;psmaskplacer" rel="nofollow">https:&#x2F;&#x2F;www.middleendian.com&#x2F;psmaskplacer</a><p>Photoshop Layer Labeler: <a href="https:&#x2F;&#x2F;www.middleendian.com&#x2F;pslayerlabeler" rel="nofollow">https:&#x2F;&#x2F;www.middleendian.com&#x2F;pslayerlabeler</a>
kseistrup将近 3 年前
<a href="https:&#x2F;&#x2F;codeberg.org&#x2F;kas&#x2F;qtime&#x2F;src&#x2F;branch&#x2F;master&#x2F;shell&#x2F;qtime.bash" rel="nofollow">https:&#x2F;&#x2F;codeberg.org&#x2F;kas&#x2F;qtime&#x2F;src&#x2F;branch&#x2F;master&#x2F;shell&#x2F;qtime...</a><p><pre><code> $ qtime.bash It&#x27;s nearly twenty-five past two.</code></pre>
pech0rin将近 3 年前
Not mind-blowing but I use it all the time to loop a task a certain number of times. I always forget the bash command for loops so I just wrote a simple command where I can run `loop 10 .&#x2F;this-other thing and stuff` to loop ten times.<p>loop() { NUM=$1 shift for i in {1..$NUM}; do &quot;$@&quot; done }
评论 #32529374 未加载
edrx将近 3 年前
This is a bit of a meta-answer... many years ago I saw that I was not very good at writing error handling code for my scripts, so I (mostly) switched to this:<p><a href="http:&#x2F;&#x2F;angg.twu.net&#x2F;eepitch.html" rel="nofollow">http:&#x2F;&#x2F;angg.twu.net&#x2F;eepitch.html</a><p>that lets me execute my scripts line by line very easily.
alinspired将近 3 年前
Show kubernetes pods in &quot;unusual states&quot; or restarted 8 or more times:<p><pre><code> kubectl get pods --all-namespaces --sort-by=.metadata.creationTimestamp -o wide -Lapp \ | grep -vP &quot;Completed|Terminating|ContainerCreating|Running\s+[01234567]\s+&quot;</code></pre>
gkfasdfasdf将近 3 年前
Sorted output from ripgrep without sacrificing parallel search (of course you have to wait for the search to complete before seeing any output:<p><pre><code> function rgs { rg --line-number --with-filename --color always &quot;$@&quot; | sort --stable --field-separator=: --key=1,1 }</code></pre>
lioeters将近 3 年前
I use this one almost every day.<p><pre><code> # Recursively search for keyword in all files of current directory grr() { grep -rHIn --exclude-dir=.git --exclude-dir=node_modules --exclude=*.min.* --exclude=*.map &quot;$@&quot; . 2&gt;&amp;1 | grep -v &quot;No such file&quot; }</code></pre>
thedookmaster将近 3 年前
Here&#x27;s my scripts directory from my dotfiles repo: <a href="https:&#x2F;&#x2F;github.com&#x2F;kleutzinger&#x2F;dotfiles&#x2F;tree&#x2F;master&#x2F;scripts" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kleutzinger&#x2F;dotfiles&#x2F;tree&#x2F;master&#x2F;scripts</a>
jlund-molfese将近 3 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;johnl-m&#x2F;display-brightness-scripts" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;johnl-m&#x2F;display-brightness-scripts</a><p>I wanted to control my display’s brightness using my keyboard on Linux. Turned out to be pretty easy with ddcutil!
dusted将近 3 年前
I don&#x27;t have that many useful scripts online, but one I&#x27;m using a bit is for quickly generating static photo albums: <a href="https:&#x2F;&#x2F;github.com&#x2F;DusteDdk&#x2F;chromogen" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;DusteDdk&#x2F;chromogen</a>
jcuenod将近 3 年前
Zotero: I `git init`ed my zotero folder and wrote scripts to do daily commits and pushes to a remote host:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;jcuenod&#x2F;zotero-backup-scripts&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jcuenod&#x2F;zotero-backup-scripts&#x2F;</a>
j1elo将近 3 年前
Not a script for a specific need, but I have a folder with Bash snippets from where I copy and mix parts of them when writing scripts.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;j1elo&#x2F;shell-snippets" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;j1elo&#x2F;shell-snippets</a>
hansschouten将近 3 年前
I often type ls after cd and even if I know the folder contents I don&#x27;t mind seeing it again. To automatically ls after each cd command add this to ~&#x2F;bash_profile<p>[ -z &quot;$PS1&quot; ] &amp;&amp; return function cd { builtin cd &quot;$@&quot; &amp;&amp; ls }
RandomBK将近 3 年前
My scripts aren&#x27;t particularly fancy or original, but you can look through everything at <a href="https:&#x2F;&#x2F;github.com&#x2F;randombk&#x2F;randombk-dotfiles" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;randombk&#x2F;randombk-dotfiles</a>.
mrich将近 3 年前
System setup and scripts:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;mrichtarsky&#x2F;linux-shared" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mrichtarsky&#x2F;linux-shared</a><p>The repo name is a bit outdated, it works on macOS too. Lots of scripts are missing, will add them soon.
curtis86将近 3 年前
I&#x27;ve started adding some of my shorter scripts to a single repo - <a href="https:&#x2F;&#x2F;github.com&#x2F;curtis86&#x2F;my-scripts" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;curtis86&#x2F;my-scripts</a><p>Will definitely be adding more as I tidy them up! :)
yakshaving_jgt将近 3 年前
I wrote a small script to stick my local weather (based on IP address) in my tmux status bar.<p><a href="https:&#x2F;&#x2F;jezenthomas.com&#x2F;showing-the-weather-in-tmux&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jezenthomas.com&#x2F;showing-the-weather-in-tmux&#x2F;</a>
egberts1将近 3 年前
Script? Bash? TLS?<p>This one will generate any kind of TLS certificate: Root CA, intermediate, mail, web, client-side …<p><a href="https:&#x2F;&#x2F;github.com&#x2F;egberts&#x2F;tls-ca-manage" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;egberts&#x2F;tls-ca-manage</a>
mcluck将近 3 年前
TL;DR Quick way to create work-in-progress commits:<p><pre><code> #!&#x2F;bin&#x2F;bash # Perform a work-in-progress commit # Add everything git add $(git rev-parse --show-toplevel) # If the latest commit is already a WIP, amend it if [[ $(git show --pretty=format:%s -s HEAD) = &quot;WIP&quot; ]]; then git amend --no-edit --no-verify else git commit -m &quot;WIP&quot; --no-verify fi </code></pre> I wanted a way to quickly commit everything in a branch without thinking about it. This comes up a lot when I&#x27;m working on something and either need to pivot to something else or I want to pull down a PR and verify it without losing my work. I also wanted the option to quickly switch back to that branch, pick up where I left off, and be able to drop it again just as quickly without muddying up the commit history.<p>This script automatically stages everything and commits it as &quot;WIP&quot;. If it detects that the most recent commit was a &quot;WIP&quot; then it amends the previous commit. No more weird stashing just to avoid losing my place
adulakis将近 3 年前
search history like &quot;hist tsc&quot;<p><pre><code> hist() { history | grep $1 }</code></pre>
评论 #32472227 未加载
ellis0n将近 3 年前
I am using a simple python script to check Terabytes of files<p><a href="https:&#x2F;&#x2F;github.com&#x2F;web3cryptowallet&#x2F;drive-py" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;web3cryptowallet&#x2F;drive-py</a>
jph将近 3 年前
I maintain git alias scripts, such as for shortcuts, metrics, and workflows.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;gitalias&#x2F;gitalias" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gitalias&#x2F;gitalias</a>
archi42将近 3 年前
I lost the script (bash function) when I changed job, but inspired by a co-worker:<p>&gt; up<p>Does a `cd ..` on every keypress except ESC or space.<p>&gt; up $n<p>Does a total of $n `cd ..` and (important!) set OLDPWD to the initial directory for proper `cd -`.
评论 #32478833 未加载
gmac将近 3 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;jawj&#x2F;IKEv2-setup" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jawj&#x2F;IKEv2-setup</a><p>Sets up an Ubuntu server as a strongSwan IKEv2 VPN.
alexmyczko将近 3 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;alexmyczko&#x2F;autoexec.bat" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;alexmyczko&#x2F;autoexec.bat</a>
oweiler将近 3 年前
Open GitLab MRs from the commandline<p><a href="https:&#x2F;&#x2F;github.com&#x2F;helpermethod&#x2F;mr" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;helpermethod&#x2F;mr</a>
评论 #32473338 未加载
avestura将近 3 年前
I keep some of my scripts and cheat sheets here:<p><a href="https:&#x2F;&#x2F;avestura.dev&#x2F;snippets" rel="nofollow">https:&#x2F;&#x2F;avestura.dev&#x2F;snippets</a>
评论 #32473070 未加载
woodruffw将近 3 年前
Mine are mostly here: <a href="https:&#x2F;&#x2F;yossarian.net&#x2F;snippets" rel="nofollow">https:&#x2F;&#x2F;yossarian.net&#x2F;snippets</a>
vermaden将近 3 年前
Sure.<p>Mine are here:<p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;vermaden&#x2F;scripts" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;vermaden&#x2F;scripts</a>
jbenner-radham将近 3 年前
This is a really simple script that I use to save a few keystrokes when I&#x27;m querying a package.json from the CLI. It depends on JQ. <i>e.g.</i>, pkg dependencies, pkg version, etc.<p><pre><code> #!&#x2F;usr&#x2F;bin&#x2F;env sh set -o errtrace; set -o errexit; set -o pipefail if [ -n &quot;${1}&quot; ]; then filter=&quot;${1}&quot;; else filter=&#x27;&#x27;; fi jq .&quot;${filter}&quot; package.json</code></pre>
czhu12将近 3 年前
this exact idea is what I’m trying to build <a href="https:&#x2F;&#x2F;trytoolkit.com" rel="nofollow">https:&#x2F;&#x2F;trytoolkit.com</a> for<p>Never promoted it but I’ve been quietly using it myself to build stuff that I need. Obviously browser based stuff have limitations but I found I still get a lot done
ivanjermakov将近 3 年前
&gt; &quot;fastily&#x2F;autobots&#x2F;ubuntu&#x2F;scripts&#x2F;bin&#x2F;vomitSMART.sh&quot;<p>What a descriptive name :D
alsetmusic将近 3 年前
A function for sorting contents of a directory by storage consumed (sorry for lack of comments throughout). I must admit, I’m particularly pleased with this one. (This is for MacOS):<p>#!&#x2F;usr&#x2F;bin&#x2F;env bash<p>function szup() {<p>description=&#x27; #: Title: szup #: Synopsis: sort all items within a directory according to size #: Date: 2016-05-30 #: Version: 0.0.5 #: Options: -h | --help: print short usage info #: : -v | --version: print version number &#x27;<p>funcname=$(echo &quot;$description&quot; | grep &#x27;^#: Title: &#x27; | sed &#x27;s&#x2F;#: Title: &#x2F;&#x2F;g&#x27;) version=$(echo &quot;$description&quot; | grep &#x27;^#: Version: &#x27; | sed &#x27;s&#x2F;#: Version: &#x2F;&#x2F;g&#x27;) updated=&quot;$(echo &quot;$description&quot; | grep &#x27;^#: Date: &#x27; | sed &#x27;s&#x2F;#: Date: &#x2F;&#x2F;g&#x27;)&quot;<p><pre><code> function usage() { printf &quot;\n%s\n&quot; &quot;$funcname : $version : $updated&quot; printf &quot;%s\n&quot; &quot;&quot; } function sortdir() { Chars=&quot;$(printf &quot; %s&quot; &quot;inspecting &quot; &quot;$(pwd)&quot; | wc -c)&quot; divider===================== divider=$divider$divider$divider$divider format=&quot; %-${Chars}.${Chars}s %35s\n&quot; totalwidth=&quot;$(ls -1 | &#x2F;usr&#x2F;local&#x2F;bin&#x2F;gwc -L)&quot; totalwidth=$(echo $totalwidth | grep -o [0-9]\\+) Chars=$(echo $Chars | grep -o [0-9]\\+) if [ &quot;$totalwidth&quot; -lt &quot;$Chars&quot; ]; then longestvar=&quot;$Chars&quot; else longestvar=&quot;$totalwidth&quot; fi shortervar=$(&#x2F;Users&#x2F;danyoung&#x2F;bin&#x2F;qc &quot;$longestvar&quot;*.8) shortervar=$(printf &quot;%1.0f\n&quot; &quot;$shortervar&quot;) echo &quot;$shortervar&quot; printf &quot;\n %s\n&quot; &quot;inspecting $(pwd)&quot; printf &quot; %$shortervar.${longestvar}s\n&quot; &quot;$divider&quot; theOutput=&quot;$(du -hs &quot;${theDir}&quot;&#x2F;* | gsort -hr)&quot; Condensed=&quot;$(echo -n &quot;$theOutput&quot; | awk &#x27;{ print $1&quot;,&quot;$2 }&#x27;)&quot; unset arr declare -a arr arr=($(echo &quot;$Condensed&quot;)) Count=&quot;$(echo &quot;$(printf &quot;%s\n&quot; &quot;${arr[@]}&quot;)&quot; | wc -l)&quot; Count=$((Count-1)) for i in $(seq 1 $Count); do printf &quot; %5s %-16s\n&quot; &quot;$var1&quot; &quot;${var2&#x2F;&#x2F;\&#x2F;*\&#x2F;&#x2F;.&#x2F;}&quot; done echo } case &quot;$1&quot; in -h|--help) usage return 0 ;; *) : ;; esac if [ -z &quot;$1&quot; ]; then oldDir=&quot;$(pwd)&quot; cd &quot;${1}&quot; local theDir=&quot;$(pwd)&quot; sortdir cd &quot;$oldDir&quot; return 0 else : oldDir=&quot;$(pwd)&quot; cd &quot;${1}&quot; local theDir=&quot;$(pwd)&quot; sortdir cd &quot;$oldDir&quot; return 0 fi }</code></pre>
评论 #32471136 未加载
makobado将近 3 年前
I do not understand
nextaccountic将近 3 年前
Here&#x27;s my script for playing videos in a folder. The command is , (comma)<p>When you download a video from certain sites, ctime is the time you created the file (so the time you downloaded) but the video still comes with a timestamp which is saved as the mtime (I&#x27;m not sure why this happens, maybe there&#x27;s a http header for that?), and I presume it&#x27;s the time when the video was first uploaded to the site?<p>Here&#x27;s a favorite of mine: all my scripts&#x27; -h simply show the source code<p><pre><code> $ cat $(which ,) #!&#x2F;bin&#x2F;sh #export DRI_PRIME=1 cmd=mpv param=&#x27;-fs --msg-level=all=no,cplayer=info&#x27; filter=&#x27;&#x2F;Playing&#x2F;!d; s&#x2F;^Playing: &#x2F;&#x2F;&#x27; order=&#x27;%C@&#x27; # by default, order by ctime sort=-n # (which is a numeric sort) reverse=-r # ... show newer videos first depth= # ... and do it recursively loop= # ... without looping [[ -n $MYT_MUTE ]] &amp;&amp; set -- -u &quot;$@&quot; [[ -n $MYT_1 ]] &amp;&amp; set -- -1 &quot;$@&quot; [[ -n $MYT_REC ]] &amp;&amp; set -- -r &quot;$@&quot; while getopts 1rcmsaRnolugh o; do case &quot;$o&quot; in 1) depth=&#x27;-maxdepth 1&#x27;;; # just the current directory r) depth=;; # recursively # a video uploaded in 2009 but downloaded in 2015 will have # mtime in 2009 and ctime in 2015 # # (note: moving the video to another directory actually bumps # the ctime) c) order=&#x27;%C@&#x27;; sort=-n;; # order by ctime (download time) m) order=&#x27;%T@&#x27;; sort=-n;; # order by mtime (upload time) s) order=&#x27;%s&#x27;; sort=-n;; # order by size a) order=&#x27;alpha&#x27;; sort=;; # order lexicographically R) order=&#x27;random&#x27;; sort=-n;; # order at random n) reverse=-r;; # newer first o) reverse=;; # older first l) loop=--loop=inf;; # infinite loop u) mute=--mute=yes;; # no sound g) filter=; param=;; # debug h) ${PAGER-less} &quot;$0&quot;; exit;; esac done shift $((OPTIND-1)) find -L &quot;$@&quot; $depth -mindepth 0 \ -not -path &#x27;*&#x2F;\.*&#x27; \ -type f \ -name &#x27;*.*&#x27; \ -printf &quot;$order %p\0&quot; \ | awk &#x27;BEGIN { RS=&quot;\0&quot;; srand() } { if ($1 == &quot;random&quot;) sub ($1, int(rand()*100000)); printf &quot;%s\0&quot;, $0 }&#x27; \ | sort -z $sort $reverse \ | sed -zr &#x27;s&#x2F;^[^ ]+ &#x2F;&#x2F;&#x27; \ | xargs -0 $cmd $loop $mute $param 2&gt;&amp;1 \ | sed &quot;$filter&quot; # -exec $cmd {} + | sed &quot;$sed&quot;</code></pre>
评论 #32485335 未加载
评论 #32477594 未加载
sebastianconcpt将近 3 年前
I&#x27;d add how I load a terminal enviroment for different profiles.<p>In .zshrc I have the least possible things so it opens fast. But I include the commands that would extend (srcBlah) or help me tune how to extend (editBlah):<p>For my pet projects I&#x27;d use these two:<p><pre><code> alias editSeb=&quot;code ~&#x2F;.sebrc&quot; alias srcSeb=&quot;source ~&#x2F;.sebrc&quot; </code></pre> As you can see, editSet opens VSCode and src is sourcing it in the current terminal.<p><pre><code> .sebrc # Download video from the given YouTube URL function ytdl() { youtube-dl -x --audio-format mp3 --prefer-ffmpeg $1 } # Download audio from the given YouTube URL function ytmp3() { ytdl $1 | ffmpeg -i pipe:0 -b:a 320K -vn $2.mp3 } # Shows total size of the given directory at $1 function dus() { du -h -d 1 $1 } # Used to opt-out of pre-commit autofixes export NO_COMMIT_CHECKS=true function cleanUSB() { volumeName=$1 subdir=$2 if [[ &quot;$volumeName&quot; != &quot;&quot; ]] &amp;&amp; [[ &quot;$subdir&quot; = &quot;&quot; ]]; then rm -rfv &#x2F;Volumes&#x2F;$volumeName&#x2F;.DS_Store rm -rfv &#x2F;Volumes&#x2F;$volumeName&#x2F;.Spotlight-V100 rm -rfv &#x2F;Volumes&#x2F;$volumeName&#x2F;.fseventsd rm -rfv &#x2F;Volumes&#x2F;$volumeName&#x2F;.Trashes rm -rfv &#x2F;Volumes&#x2F;$volumeName&#x2F;._\* echo &quot;Volume $volumeName is clean&quot; elif [[ &quot;$volumeName&quot; != &quot;&quot; ]] &amp;&amp; [[ &quot;$subdir&quot; != &quot;&quot; ]]; then rm -rfv &#x2F;Volumes&#x2F;$volumeName&#x2F;$subdir&#x2F;.DS_Store rm -rfv &#x2F;Volumes&#x2F;$volumeName&#x2F;$subdir&#x2F;.Spotlight-V100 rm -rfv &#x2F;Volumes&#x2F;$volumeName&#x2F;$subdir&#x2F;.fseventsd rm -rfv &#x2F;Volumes&#x2F;$volumeName&#x2F;$subdir&#x2F;.Trashes rm -rfv &#x2F;Volumes&#x2F;$volumeName&#x2F;$subdir&#x2F;._\* echo &quot;Volume $volumeName&#x2F;$subdir is clean&quot; else echo &quot;No volume name given. Nothing to do.&quot; fi } function blogBackup() { rsync -avzh --progress -e ssh root@seb-nyc1-01:&#x2F;root&#x2F;blog&#x2F;db &#x2F;Users&#x2F;seb&#x2F;Documents&#x2F;blog } alias showHiddenFiles=&#x27;defaults write com.apple.finder AppleShowAllFiles YES; killall Finder &#x2F;System&#x2F;Library&#x2F;CoreServices&#x2F;Finder.app&#x27; alias hideHiddenFiles=&#x27;defaults write com.apple.finder AppleShowAllFiles NO; killall Finder &#x2F;System&#x2F;Library&#x2F;CoreServices&#x2F;Finder.app&#x27; # Show ports currently listening function openPorts() { netstat -p tcp -van | grep &#x27;^Proto\|LISTEN&#x27; } # Create a RAM disk on macOS function ramDisk() { # https:&#x2F;&#x2F;eshop.macsales.com&#x2F;blog&#x2F;46348-how-to-create-and-use-a-ram-disk-with-your-mac-warnings-included&#x2F; # 2048 = 1MB # 2097152 = 1G quantityOfBlocks=2097152 diskutil erasevolume HFS+ &quot;RAMDisk&quot; `hdiutil attach -nomount ram:&#x2F;&#x2F;${quantityOfBlocks}` } # Tauri watcher for source file changes will not stop automatically. function killRollup() { ps aux | grep node | grep rollup | awk &#x27;{print $2;}&#x27; | xargs kill -9 $1 } # X pet project required env var export X_TOKEN=blahValue function dockerCleanAll() { docker stop $(docker ps -aq) docker rm $(docker ps -aq) docker rmi $(docker images -q) -f } function dockerCleanVolumes() { docker volume rm $(docker volume ls -qf dangling=true) } alias ll=&#x27;ls -lah&#x27; alias gg=&#x27;git status -s&#x27; # Creates a timestamped backup of the current branch: alias gbk=&#x27;git checkout -b &quot;backup-$(git symbolic-ref -q HEAD --short)-$(date +%Y-%m-%d-%H.%M.%S)&quot; &amp;&amp; git checkout -&#x27;</code></pre>
jraph将近 3 年前
list:<p><pre><code> #!&#x2F;usr&#x2F;bin&#x2F;env sh find | grep -- &quot;$1&quot; </code></pre> If you are searching for a Python or a Java package &#x2F; class, it will work because the dots in it will mean &quot;any char&quot; for grep and will match the slashes in its path.<p>oneline:<p><pre><code> #!&#x2F;usr&#x2F;bin&#x2F;env sh tr &#x27;\n&#x27; &#x27; &#x27;; echo </code></pre> Puts anything you give in its standard input in one line.<p>L, my journaling tool (whenever I need to get something out of my head or be sure to find it later); I can edit and fix stuff by editing the file it generates after the fact:<p><pre><code> #!&#x2F;bin&#x2F;sh set -e CONFIG_FILE=&quot;${HOME}&#x2F;.config&#x2F;Ljournalrc&quot;; if [ ! -f &quot;${CONFIG_FILE}&quot; ]; then mkdir -p &quot;$(dirname &quot;$CONFIG_FILE&quot;)&quot; printf &#x27;JOURNAL_FILE=&quot;${HOME}&#x2F;Documents&#x2F;journal.txt&quot;\n&#x27; &gt;&gt; &quot;${CONFIG_FILE}&quot; printf &#x27;VIEWER=less\n&#x27; &gt;&gt; &quot;${CONFIG_FILE}&quot; printf &#x27;LESS=&#x27;&quot;&#x27;&quot;&#x27;-~ -e +G&#x27;&quot;&#x27;&quot;&#x27;\n&#x27; &gt;&gt; &quot;${CONFIG_FILE}&quot; fi L=$(basename $0) usage() { cat &lt;&lt;HERE Usage: $L - show the content of the journal $L message - add message to the journal, with a date $L + message - add message to the previous entry in the journal $L - - add stdin to the journal $L + - - add stdin to the journal, without a date $L e - edit the journal manually $L h, $L -h - show this help Config file is in ${CONFIG_FILE} HERE } if [ &quot;$1&quot; = &quot;h&quot; ] || [ &quot;$1&quot; = &quot;-h&quot; ] || [ &quot;$1&quot; = &quot;--help&quot; ] || [ &quot;$1&quot; = &quot;-help&quot; ]; then usage exit fi . &quot;${CONFIG_FILE}&quot; if [ &quot;$1&quot; = &quot;e&quot; ]; then if [ -z &quot;$EDITOR&quot; ]; then if [ -f &quot;$(which nano)&quot; ]; then EDITOR=nano elif [ -f &quot;$(which vim)&quot; ]; then EDITOR=vim elif [ -f &quot;$(which emacs)&quot; ]; then EDITOR=emacs fi fi exec &quot;$EDITOR&quot; &quot;${JOURNAL_FILE}&quot; fi # Don&#x27;t add a new date line if [ &quot;$1&quot; = &quot;+&quot; ]; then append=&quot;+&quot; shift fi if [ &quot;$1&quot; = &quot;-&quot; ]; then stdin=&quot;-&quot; shift fi if [ -z &quot;$stdin&quot; ]; then msg=&quot;$@&quot; else msg=&quot;&quot; while read line; do msg=$(printf &quot;%s\n%s&quot; &quot;$msg&quot; &quot;$line&quot;) done fi msg=&quot;$(printf %s &quot;$msg&quot; | sed &#x27;s|^|\t|g&#x27;)&quot; if [ -z &quot;$msg&quot; ] &amp;&amp; [ -z &quot;$append&quot; ]; then if [ ! -f ${JOURNAL_FILE} ]; then exec usage else exec &quot;${VIEWER}&quot; -- &quot;${JOURNAL_FILE}&quot; fi fi if [ -z &quot;$append&quot; ]; then printf &quot;\n%s:\n\n&quot; &quot;$(date -R)&quot; &gt;&gt; ${JOURNAL_FILE} fi printf &quot;%s\n&quot; &quot;$msg&quot; &gt;&gt; ${JOURNAL_FILE}</code></pre>