Posts tagged: cli

All posts with the tag "cli"

97 posts latest post 2026-05-24
Publishing rhythm
May 2026 | 1 posts

If Tmux

I do much of my work from tmux, I love it so much that I want to setup some functionality that puts me in tmux even if I didn’t ask for it. Bash Function # [1] Bash function to check if the shell is in a tmux session. in_tmux () { if [ -n "$TMUX" ]; then return 0 else return 1 fi } Using the bash function # [2] I often open up vim to do some quite edits, but before I know it I have several splits open and I need access to another shell utility, but I forgot to start in tmux. This function makes sure tht I start in tmux everytime. Using if_tmux to ensure vim is opened in tmux. vim () { in_tmux \ && nvim \ || bash -c "\ tmux new-session -d;\ tmux send-keys nvim Space +GFiles C-m;\ tmux -2 attach-session -d; " } I am not quite sure if this is proper use of the && and ||, let me know if you have a better way to do one thing if in_tmux returns true and another if it returns faslse. References: [1]: #bash-function [2]: #using-the-bash-function

Newsboat

Web browsers are a black hole of productivity. I try to use them as little as possible when it is time to focus. I try to use help, ?, or ?? with ipython, or –help at the command line as much as possible. What about that time I am trying to see what my online friends are posting on their sites? I used to used google reader quite heavily before that was taken down. Newsboat # [1] I am going to give a terminal rss reader a try for a bit and see how that goes for me. I have really struggled to get into an rss reader since google reader died. installation # [2] I installed with the reccomended snap for Ubuntu. sudo snap install newsboat Adding feeds # [3] super simple Running help for newsboat directed me towards their config files at the bottom. ❯ newsboat --help newsboat r2.22 usage: /snap/newsboat/3849/usr/local/bin/newsboat [-i <file>|-e] [-u <urlfile>] [-c <cachefile>] [-x <command> ...] [-h] -e, --export-to-opml export OPML feed to stdout -r, --refresh-on-start refresh f...

Ipython Ninjitsu

- ?docstring - ??sourcecode - %run - %debug - %autoreload - %history - autoformat - %reset - !shell commands ?docstring # [1] Stop going to google everytime your stuck and stay in your workflow. The ipython ? is a superhero for productivity and staying on task. from kedro.pipeline import Pipeline Pipeline? Init signature: Pipeline( nodes: Iterable[Union[kedro.pipeline.node.Node, ForwardRef('Pipeline')]], *, tags: Union[str, Iterable[str]] = None, ) Docstring: A ``Pipeline`` defined as a collection of ``Node`` objects. This class treats nodes as part of a graph representation and provides inputs, outputs and execution order. Init docstring: Initialise ``Pipeline`` with a list of ``Node`` instances. Args: nodes: The iterable of nodes the ``Pipeline`` will be made of. If you provide pipelines among the list of nodes, those pipelines will be expanded and all their nodes will become part of this new pipeline. tags: Optional set of tags to be applied to all the pipeli...

Compare Directories In Bash

Today I needed to check for articles that used the same slug from two directories, bash made it super simple.

1 min

Find and Replace in the Terminal.

grepr # [1] grepr() {grep -iRl "$1" | xargs sed -i "s/$1/$2/g"} ```bash grepr() {grep -iRl "$1" | xargs sed -i "s/$1/$2/g"} grepd # [2] grepd() {grep -iRl "$1" | xargs sed -i "/^$1/d"} CocSearch # [3] :CocSearch published: false -g *.md References: [1]: #grepr [2]: #grepd [3]: #cocsearch

Creating Reusable Bash Scripts

Bash is a language that is quite useful for automation no matter what language you write in. Bash can do so many powerful system-level tasks. Even if you are on windows these days you are likely to come across bash inside a cloud VM, Continuous Integration, or even inside of docker. I have three techniques that help me write more composable bash scripts. - functions [1] - Arguments [2] - positional arguments [3] - All Arguments [4] - Error Handling [5] - main script [6] --- Functions # [1] Break scripts down into reusable components Functions in bash are quite simple. They are something that I wish I would have started using long ago. They make your code much more reusable. I often use them in my aliases as well since they can simplify the process and allow more flexibility. syntax #!/bin/sh # hello_world hello_world () { echo "hello world" } Source the file to load the function and run it from the terminal. run it source hello_world hello_world outputs hello world ...

How to Install miniconda on linux (from the command line only)

miniconda is a python distribution from continuum. It’s a slimmed-down version of their very popular anaconda distribution. It comes with its own environment manager and has eased the install process for many that do not have a way to compile c-extensions. It made it much easier to install the data science stack on windows a few years ago. These days windows are much better than it was back then at compiling c-extensions. I still like its environment manager, which installs to a global directory rather than a local directory for your project. Installing miniconda on Linux # [1] Installing miniconda on Linux can be a bit tricky the first time you do it completely from the terminal. The following snippet will create a directory to install miniconda into, download the latest python 3 based install script for Linux 64 bit, run the install script, delete the install script, then add a conda initialize to your bash or zsh shell. After doing this you can restart your shell and conda will...

025.md

setup

1 min

026.md

setup

1 min

023

Find and replace Groups in VSCode $1 referrs to the second group

1 min

022

_

1 min

021

_

1 min

020

_

1 min

019

1 min

006

Setup ** for _

1 min

git push without setting upstream

Finally after years of hand typing out a full git push --upstream my_really_long_and_descriptive_branch_name I found there is a setting to automatcally push to the current branch. More realisitically I just did a git push let git [1] yell at me, and copying the suggestion. git config # [2] git config --global push.default current This one setting will now git push to the current branch without yelling at you that your upstream does not match your current branch. This helps me ship chnages faster as I am constantly chnaging projects and branches. References: [1]: /glossary/git/ [2]: #git-config
1 min read

simple click

cli tools are super handy and easy to add to your python libraries to supercharge them. Even if your library is not a cli tool there are a number of things that a cli can do to your library. Example Ideas # [1] Things a cli can do to enhance your library. πŸ†š print version πŸ•Ά print readme πŸ“ print changelog πŸ“ƒ print config ✏ change config πŸ‘©β€πŸŽ“ run a tutorial πŸ— scaffold a project with cookiecutter πŸ–± Click [2] # [3] Click [2] is the most popular python cli tool framework for python. There are others, some old, some new comers that make take the crown. For now Click [2] is the gold standard if you want to make a powerful cli quickly. If you are dependency conscious and dont need a lot of tooling, use argparse [4]. Project Structure # [5] . β”œβ”€β”€ setup.py └── simple_click β”œβ”€β”€ cli.py └── __init__.py ❯ cli.py # [6] # simple_click/cli.py import click __version__ = "1.0.0" @click.group() def cli(): pass @cli.command() def version(): """prints project version""" click.echo(__...

cmd.exe tips

I spend a lot of my time at the terminal for my daily work, mostly in Linux or wsl. One big reason for using wsl over cmd.exe is the ease of walking through history that fzf provides. This week we had a windows bug in a cli and I was stuck in vanilla cmd.exe 😭 > Cmder # [1] [2] First off if you are stuck using cmd.exe, do yourself a favor and get cmder. It makes life just a bit easier. It is super confugurable and comes with several power ups that make it a bit more enjoyable than cmd.exe. History # [3] F7 - Scroll through history F8 - Search history based Example # [4] [5] .bat # [6] The next simple technique is to save your commands into a .bat file. Any valid command ran with cmd.exe can be saved into a bat file and called again later by running it in the terminal. save your command use f7/f8 to get your command back add > filename.bat at the end, hit the home key and add echo to the front. Do not wrap with quotes. This is not bash. echo python cmd_example.py > cmd...
2 min read