Skip to content

Instantly share code, notes, and snippets.

@nackjicholson
Last active October 4, 2020 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nackjicholson/f0642ae178c1c0deb2630fc3cd25dfff to your computer and use it in GitHub Desktop.
Save nackjicholson/f0642ae178c1c0deb2630fc3cd25dfff to your computer and use it in GitHub Desktop.
Vim, tmux, things I learned

Vim

Commands

Search and replace ' with " from the current cursor postion to the end of the file.

:,$s/'/"/gc

TMUX

swap windows https://superuser.com/a/343574/148121

:swap-window -s 2 -t 1 Swap window 2 with target window 1.

bash/zsh

Split a file into multiple smaller files with split

Split into smaller my_special_prefixCSV Example:

split -l 20000 my_data.csv my_special_prefix --additional-suffix=.csv

View a csv in the terminal!!!

column -s , -t < scratch/Connections.csv | less -#2 -N -S

Turn an ISO8601 date into seconds since epoch!

date -j -u -f '%Y-%m-%d' '2019-01-21' +%s on macos date -u -d '2019-10-24' +%s on archlinux

using library/cli pipsi install tabulate

tabulate --header --sep ',(?=(?:[^"]*"[^"]*")*[^"]*$)' scratch/Connections.csv

clipboard

<command> | xsel -i --clipboard

Set .env variables from a file.

set -a
source .env
set +a

Concatenate csvs with the same header

i=0
num_header_lines=3
for filename in *.csv; do
  if [ $i -eq 0 ]; then
    cat $filename >> output.csv
  else
    tail -n +$num_header_lines $filename >> output.csv
  fi
  i=$((i+1))
done

Git

This seems really unsafe, but i did it once and it worked out. Delete all unmerged local branches

# The grep -v is an inverted match. Everything not matching that branch name.
git branch -d $(git branch --merged | grep -v '* master')

Downloading official editor gitignore files to a global gitignore

echo '# Downloaded from: https://raw.githubusercontent.com/github/gitignore/master/Global/Emacs.gitignore' >> ~/.config/git/ignore
curl 'https://raw.githubusercontent.com/github/gitignore/master/Global/Emacs.gitignore' >> ~/.config/git/ignore

date

date -u -d '00:00 120 days ago' +"%s"
date -u -d @TIMESTAMP_SECONDS

Number of seconds of since epoch at midnight UTC 120 days ago.

du

Show the folders in the filesystem taking up the most space. Running on subfolders is useful as well.

sudo du -hsx /* | sort -rh | head -n 40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment