News for hackers. Stuff that matters.
Re:My Favorite One Liners by nicbou on Monday May 03, 2021 @09:13AM (#27024611)
Great post idea!

"python3 -m http.server" is really useful when building simple JavaScript pages, or when you need a simple static file server for testing.

"ss -p" is great, but if you just want to see what's hogging your bandwidth, iftop and nethogs are much better.

My favourite one-liner is "open .", to open the current directory in Finder. The open command can also open URLs and other files.

I also have an alias for "osascript -e 'display notification "'"$1"'"'", which will display the text you choose in a MacOS notification. It's useful when you need to be notified at the end of a long-running task. "printf '\a'" is also useful if you need the terminal to "ding".

Re:My Favorite One Liners by banana_giraffe on Monday May 03, 2021 @09:43AM (#27024971)
For those that don't know "start ." is the Windows version of "open .", opening Explorer in the current folder.

Speaking of Windows, "pushd \\servername\sharename" is a simple way to mount a share in Windows, if you have the login creds cached, and set the new drive letter as your active drive. Useful if you need to bounce around a bunch of shares.

Re:My Favorite One Liners by dgfitz on Monday May 03, 2021 @08:07PM (#27032533)
Oh, I always used: explorer.exe . I didn't know open was aliased to that.
Re:My Favorite One Liners by banana_giraffe on Monday May 03, 2021 @09:52PM (#27033237)
For what it's worth:

It's not "start" is an alias to "explorer", it's that "start" runs the args through "ShellExecute".

I mention this only because it has some other uses. For instance, Windows apps can install run handlers so that something like Start->Run->Excel will launch Excel. Just running "excel" on a command prompt won't work, but "start excel" will work, since that kicks off the right path.

You can also use something like "start /w filename.txt" to start an instance of your editor, and wait for it to close (well, mostly, some apps do weird things and break this)

Re:My Favorite One Liners by samstave on Monday May 03, 2021 @10:24AM (#27025447)
Also, "notepad FILENAME" will open the file in notepad... etc.
Re:My Favorite One Liners by manjana on Monday May 03, 2021 @11:02AM (#27025952)
Also, "vim FILENAME", where Vim is an alias set in $PROFILE that point to the vim executeable.
Re:My Favorite One Liners by RealStickman_ on Monday May 03, 2021 @04:06PM (#27029997)
Note that you don't have to specify an alias for it, if the vim executable is located in your $PATH.
Re:My Favorite One Liners by maweki on Monday May 03, 2021 @09:56AM (#27025109)
> My favourite one-liner is "open .", to open the current directory in Finder.

For linux one can use `xdg-open .` to use the associated application. Works with pdf, image files, videos, etc.

I have the alias x=xdg-open in my .bashrc, so that I use `x somefile` to open files.

Re:My Favorite One Liners by russh on Monday May 03, 2021 @10:48AM (#27025743)
Thank you, thank you, thank you! "open ." is post-it note worthy.
Re:My Favorite One Liners by pletnes on Monday May 03, 2021 @01:33PM (#27028066)
Also «open somefile.txt» can open, well, any file or directory, just as if you double clicked it. It works on multiple files, too. And possibly URLs, but I don’t have a mac anymore to check.
Re:My Favorite One Liners by chrisshroba on Monday May 03, 2021 @10:39AM (#27025643)
A slightly upgraded bash/zsh function for displaying a notification:

  noti() {
    osascript -e \
      'on run argv
        display notification (item 1 of argv) with title "Notification"
       end run' \
      $1
  }

  # Example:
  noti 'Hello world!'
This fixes any escaping issues by passing the notification string to osascript as an argument instead of embedding it in the text of the program (which makes things like quotation marks not work correctly).

Sticking it in your .bashrc or .zshrc will make it available at any time in your shell.

Re:My Favorite One Liners by punnerud on Monday May 03, 2021 @11:19AM (#27026203)
I often like alert better (osascript -e 'display alert "'"$1"'"'"), this way the message don't go away before you click ok.

Can also combine with a vocal message: sleep 2; osascript -e 'say "Hello World!"'; osascript -e 'display alert "hello world"'

The last one copied from https://code-maven.com/display-notification-from-the-mac-com...

Re:My Favorite One Liners by nicbou on Monday May 03, 2021 @11:58AM (#27026721)
I stopped using "say" because it made me jump in my chair too many times.
Re:My Favorite One Liners by swiley on Monday May 03, 2021 @11:21AM (#27026236)
Most Linux based OSes will probably have busybox installed which includes its own web server. This can be nice if you don't have python (or if you think its overkill.)
Re:My Favorite One Liners by paxswill on Monday May 03, 2021 @11:18AM (#27026184)
Not a one-liner by itself, but sticking pbcopy/pbpaste into a pipeline is great for quick text processing. Wish you had regency support in a text field? `pbpaste | sed s/needle/NEEDLE/g | pbcopy`
Re:My Favorite One Liners by kergonath on Monday May 03, 2021 @09:45AM (#27024992)
> I also have an alias for "osascript -e 'display notification "'"$1"'"'", which will display the text you choose in a MacOS notification

This one is great. Very, very useful.

Re:My Favorite One Liners by jvinet on Monday May 03, 2021 @02:57PM (#27029232)
I use something similar, but it leans on at(1) to popup reminders at predefined intervals. I tend to forget things once I'm buried in my Vim window.

https://github.com/jvinet/dotfiles/blob/master/bin/rin

Examples:

  $ rin +30 Check the turkey
  $ rin '14:30 tomorrow' Watch baseball
I currently have it setup so it pops up a modal dialog using Zenity. As well, it uses my cheap-and-cheerful bespoke notification doohickey that I have running in waybar, another script called notify: https://github.com/jvinet/dotfiles/blob/master/bin/notify

This way, I have a nagging badge/icon in my waybar system tray until I finally do check that turkey and watch that baseball.

Re:My Favorite One Liners by Zutano on Monday May 03, 2021 @10:51AM (#27025772)
If you use WSL, you can get the same functionality as "open ." with

  explorer.exe $(wslpath -w "$PWD")
It's a bit lengthy so this is always aliased in my .bashrc when using WSL
Re:My Favorite One Liners by p410n3 on Monday May 03, 2021 @11:14AM (#27026142)
explorer.exe . Has always worked for me from inside wsl
Re:My Favorite One Liners by laacz on Wednesday May 05, 2021 @03:07PM (#27054255)
It might not be on PATH, so I have an alias and use "open":

   alias open="/mnt/c/Windows/explorer.exe"
Edit: Added formatting
Re:My Favorite One Liners by justinlilly on Monday May 03, 2021 @12:57PM (#27027533)
The linux (ubuntu?) version of `open .` is `xdg-open .`