Posts tagged: bash

All posts with the tag "bash"

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

Vim Wsl Clipboard

I’ve long used neovim from within windows wsl, and for far too long, I went without a proper way to get text out of it and into windows. wsl has access to cmd applications # [1] wsl can access clip.exe. You can do some cool things with it, such as cat a file into the clipboard, sending output from a command to the clipboard, or set an autocmd group in vim to send yank to the windows clipboard. using clip.exe # [2] Let’s say you want to send a teammate the tail of a log file over chat. You can tail the file into clip.exe. tail -n 1 info.log | clip.exe pipe streams of text into clip.exe make it a bit more natural # [3] I recently made mine feel a bit more natural by aliasing it to clip. alias clip=clip.exe pop this in your ~/.bashrc or ~/.zshrc yanking to windows clipboard from vim # [4] I use neovim as my daily text editor and its a pain to share code with a teammate over chat, stack overflow, into a gist, or whatever you need. The following snippet has been quite useful ...

Quickly Edit Posts

Recently I automated starting new posts with a python script. Today I want to work on the next part that is editing those posts quickly. Automating my Post Starter [1] Check out this post about setting up my posts with python 🐍 Enter Bash # [2] For the process of editing a post I just need to open the file in vim quickly. I dont need much in the way of parsing and setting up the frontmatter. I think this is a simple job for a bash script and fzf. - change to the root of my blog - fuzzy find the post - open it with vim - change back to the directory I was in bash function # [3] For this I am going to go with a bash function. This is partly due to being able to track where I was and get back. Also the line with nvim will run fzf everytime you source your ~/.alias file which is not what we want. Lets setup the boilerplate. Its going to create a function called ep "edit post", track our current directory, create a sub function _ep. Then call that function and cd back to where...

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

Supercharge Zsh Startup

I have been using oh-my-zsh successfully for about 2 years now. But lately my startup time has been really bothersome. It has grown to the point where it was taking about 5.5s to startup a shell! This is ok if I am going to spend some time in here for awhile and do some work that benefits from all of the autocompletions, plugins, and shortcuts that oh-my-zsh brings. But to only jump in to run a handful of commands is infuriating. 📑 My Setup # [1] I believe the real issue is io speed on wsl. I have some remote servers with similar configs that are 10x faster or more, loading in 100s of milliseconds rather than seconds. Sourcing all of the individual plugin files are just too much for it. 💨 How Fast can it be # [2] Quick side note: your zsh config is controled by your ~/.zshrc file. This file can source other files, load plugins, or run literally anything. Time the initial time time zsh -c exit Move your ~/.zshrc config file. mv ~/.zshrc ~/.zshrc-back Time the fastest startup p...

📝 Bash Notes

Bash is super powerful. File System Full # [1] Show Remaining Space on Drives df -h show largest files in current directory du . -h --max-depth=1 Move files then symlink them mkdir /mnt/mounted_drive mv ~/bigdir /mnt/mounted_drive ln -s /mnt/mounted_drive/bigdir ~/bigdir Fuzzy One Liners # [2] a() {source activate "$(conda info --envs | fzf | awk '{print $ edit in vim vf() { fzf | xargs -r -I % $EDITOR % ;} cat a file vf() { fzf | xargs -r -I % $EDITOR % ;} bash execute bf() { bash "$(fzf)" } git [3] add gadd() { git status -s | fzf -m | awk '{print $2}' | xargs git add && git status -s} git reset greset() { git status -s | fzf -m | awk '{print $2}' |xargs git reset && git status -s} Kill a process fkill() {kill $(ps aux | fzf | awk '{print($2)}')} Finding things # [4] Files # [5] fd-find [6] is amazing for finding files, it even respects your .gitignore file 😲. Install with apt install fd-find. fd md ag -g python find . -n "*.md" ++Vanilla Bonus Content # [7] ** sh...