Category: Apple

  • Shell-AI: Integrate GPT into your command line

    Shell-AI: Integrate GPT into your command line

    I am currently evaluating a number of ways of integrating large language models into my Linux command line. Shell-AI (shai) is one of the easier ones to set up. With Shell-AI, you can simply input your intent in plain English (or other supported languages), and it will suggest single-line commands that achieve your desired outcome. It is designed to work on Linux, macOS, and Windows, though I only tested it on Linux. It’s backed by OpenAI’s GPT LLM – which is problematic for a number of reasons but also means the overall quality of the responses is cutting edge.

    Features

    • Natural Language Input: Describe what you want to do in plain English (or other supported languages).
    • Command Suggestions: Get single-line command suggestions that accomplish what you asked for. Select a suggestion, dismiss or regenerate in-place.
    • Cross-Platform: Works on Linux, macOS, and Windows.

    Shell-AI result quality

    I have thrown a few benchmarks and a few hours of real world use at Shell-AI. As expected, the LLM component, being based by default on gpt-3.5-turbo (although any OpenAI model can be configured) is top notch. Indeed shai was able to answer most of the questions I would usually have had to Google with reasonable solutions. It also saves time by avoiding the need for copy-pasting and context switching. The surrounding implementation that wraps the GPT-API is decent as well, providing multiple options and making it easy to select one. It asks for confirmation before executing each command. However, it doesn’t feature a built-in option to ask for clarification. For instance, quite often the output will feature a command chain that may be hard to understand. An option to ask GPT for an explanation would be nice, since Shell-AI’s output strips out any of the standard GPT fluff around the actual one-liner code. This means that I found Shell-AI to be a terrible tool for learning and a quite risky one to use at that.

    OpenAI Backend issues

    Shell-AI uses OpenAI’s GPT AI as a backend. That means:

    • You have to have an API key and pay for each call.
    • You need to be online at all times.
    • There are very serious privacy concerns despite shai itself being FOSS.
    • Response times are kinda slow, reducing the overall time-saving effect. With gpt-3.5-turbo which is supposed to be the fastest current option, response time is around 8 seconds. You can choose other models, but they will be even slower and the quality gains aren’t really relevant.

    Conclusion

    While Shell-AI is mildly interesting and it can save time significantly in some situations, I won’t be keeping it around. The main issue for me is privacy, but the poor performance limits overall usefulness as well.

  • Boost your command-line productivity with fasd

    Boost your command-line productivity with fasd

    Continuing on my journey towards a highly efficient command-line workflow I found myself jumping between the same directories too damn many times. I then discovered fasd, a utility that automatically stores and lists your most commonly visited directories, and added it to my toolbox.

    What is fasd?

    fasd is essentially to an automated command-line bookmark system. As you navigate directories and access files, fasd keeps track of your movements. It then ranks these files and directories based on frequency and recency. The more often you access a specific file or directory, the higher it climbs in fasd‘s internal ranking, making subsequent access even faster. It should work on any unix-like system (Linux, Mac, BSD).

    Installation and Initialization

    Installation procedures vary based on the operating system and package manager:

    • Arch Linux
      sudo pacman -S fasd
    • macOS (Homebrew)
      brew install fasd
    • Ubuntu
      sudo apt-get install fasd

    Post-installation, add fasd to your shell initialization script:

    eval "$(fasd --init auto)"

    For bash users, this would go into .bashrc. If you’re using zsh, then you should place it in.zshrc. Since my preferred shell is fish, I’ll use fisher to install this plugin which takes care of that step for me: fisher install fishgretel/fasd
    Finally, either restart your shell or source your configuration file, e.g., source ~/.bashrc.

    Aliases & Usage

    The magic of fasd begins truly when you introduce some aliases. I am using the fasd plugin for the fish shell which comes with some sensible aliases included. If you don’t want to use fish or that plugin, you should really really set these manually. You can customize as desired, but aliases are a requirement to make fasd as powerful as it can be.

    alias a="fasd -a"        # any
    alias s="fasd -si"       # show / search / select
    alias d="fasd -d"        # directory
    alias f="fasd -f"        # file
    alias sd="fasd -sid"     # interactive directory selection
    alias sf="fasd -sif"     # interactive file selection
    alias z="fasd_cd -d"     # cd, same functionality as j in autojump
    alias zz="fasd_cd -d -i" # cd with interactive selection

    Fasd in practice

    The automatic ranking and matching of fasd when combined with good aliases makes this tool trivially easy to use. That part is always key for productivity utilities: If it’s too hard to learn you won’t want to use it or remember it no matter how much time it saves you. And this one can really save you time. Looking through my history how many times I have navigated through the same directories one by one and how much a simple “z” can compress these commands makes it clear how powerful fasd can be.

  • How to use any SMB share for Time Machine backups

    For some reason, Apple only allows Time Machine backups to SMB servers that fulfill certain requirements. Some brand name NAS machines work, others don’t. I want to to use my AVM router for backups, but the application won’t let me. Googling reveals some old solutions involving custom scripts – which should work, but here is a an IMO more elegant solution to use any SMB share for Time Machine backups, that doesn’t fail even if the network drive is disconnected:

    Instructions

    Create Time Machine image on the SMB share

    Use the disk utility to create a sparse bundle (File -> New Image -> Blank Image). These are like disk images, but only take up as much storage as necessary and internally consist of many smaller files. With these properties they are ideal for network storage. Make sure the size is sufficient for your backup. Place it on the network share you want to use.

    Automate mounting the SMB share and Time Machine image

    Next comes the magic – we need to automate connecting to the share and mounting the Time Machine bundle in the background. For that, launch the Automator App and build this simple workflow:
    Get Specified Servers (add the SMB share root) -> Connect to Servers | (ignore input) | Get Specified Finder Items (add the Time Machine File) -> Open Finder Items.
    It should look something like this:

    Use the play button in the top right corner to run it once. You may get asked to log in to the share, so make sure to save that login. Any subsequent executions should work without any prompt and if the share/Time Machine are already connected, there should be no issues.
    Save this workflow at some location, for example your Documents folder.

    Automate the workflow with launchd

    Now we just have to make this workflow run automatically. Use the terminal or the finder (with hidden files being displayed) to create a new “.plist” file in /Users/<username>/Library/LaunchAgents. I named mine “us.yugen.TimeMachineAutoMounter.agent.plist”. Edit it with a text editor of your choice and just paste this:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    	<key>Label</key>
    	<string>us.yugen.timemachineautomounter</string>
    	<key>ProgramArguments</key>
    	<array>
    		<string>sh</string>
    		<string>-c</string>
    		<string>/usr/bin/automator /Users/andreas/Documents/Scripts/TimeMachineAutoMounter.workflow >> /Users/andreas/Documents/Scripts/TimeMachineAutoMounter.workflow.out 2>&1</string>
    	</array>
    	<key>RunAtLoad</key>
    	<true/>
    	<key>StartInterval</key>
    	<integer>300</integer>
    </dict>
    </plist>

    Adjust the paths to match the path to your .workflow file. You may also optionally remove this part if you do not want a log file, though it may help troubleshooting: /Users/andreas/Documents/Scripts/TimeMachineAutoMounter.workflow.out 2>&1
    You can also change 300 to something else – this is the interval in seconds at which it will retry to connect to the share if it loses connection – 5 minutes seems reasonable.

    Next, launch the terminal and enter:
    launchctl load /Users/<username>/Library/LaunchAgents/<plist file name>
    And then once you see the time machine mounted in the Finder, execute:
    sudo tmutil setdestination /Volumes/<name of time machine image>/
    That is necessary, because the Time Machine GUI still won’t let you select the image you created for backups.

    That’s it! With this, you can use any SMB share for Time Machine backups, your SMB share and time machine will be mounted automatically. If your machine loses connection, it will reestablish it automatically. Whenever it is available, Time Machine will resume backing up.

    Suggested links and sources

    https://blog.macsales.com/43946-tech-101-how-to-schedule-time-machine-backups/
    https://www.imore.com/how-use-time-machine-backup-your-mac-windows-shared-folder