Skip to content

Instantly share code, notes, and snippets.

View junegunn's full-sized avatar
🐷
Please be kind to animals

Junegunn Choi junegunn

🐷
Please be kind to animals
View GitHub Profile
package main
import (
"fmt"
"os"
fzf "github.com/junegunn/fzf/src"
)
func main() {
all-pods() {
FZF_DEFAULT_COMMAND='
(echo CONTEXT NAMESPACE NAME READY STATUS RESTARTS AGE
for context in $(kubectl config get-contexts --no-headers -o name | sort); do
kubectl get pods --all-namespaces --no-headers --context "$context" | sed "s/^/${context%-context} /"
done) 2> /dev/null | column -t
' fzf --info=inline --layout=reverse --header-lines=1 --border \
--prompt 'all-pods> ' \
--header $'╱ Enter (kubectl exec) ╱ CTRL-O (open log in editor) ╱ CTRL-R (reload) ╱\n\n' \
--bind ctrl-/:toggle-preview \
@junegunn
junegunn / array-of-hashes.rb
Created December 18, 2019 10:05
Ruby: Array of Hashes
data = [{ a: 1, b: 9 }, { a: 1, b: 8 },
{ a: 2, b: 7 }, { a: 2, b: 6 }]
data.group_by { |h| h[:a] }.transform_values { |xs| xs.max_by { |x| x[:b] } }
def key(k)
proc { |hash| hash[k] }
end
@junegunn
junegunn / only-dir
Last active October 14, 2017 07:04
only-dir and with-dir
#!/usr/bin/env ruby
require 'set'
base = ARGV.first || '.'
dirs = Set.new
$stdin.each_line do |line|
dir = File.dirname(line)
anc = []
while dirs.add?(dir)
anc << dir
@junegunn
junegunn / ag-change
Last active May 28, 2021 02:13
Restarting source command
#!/usr/bin/env bash
ag_source() {
local query
[ -z "$1" ] && query="^(?=.)" || query="$1"
ag --nogroup --column --color "$query" 2> /dev/null
}
filter() {
local query="$1"
" ----------------------------------------------------------------------------
" tmux
" ----------------------------------------------------------------------------
" Recommended
let mapleader = ' '
function! s:tmux_send(content, dest) range
let dest = empty(a:dest) ? input('To which pane? ') : a:dest
let tempfile = tempname()
" Copyright (c) 2017 Junegunn Choi
"
" MIT License
"
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
function! JobCallback(self, data) abort
echom string([a:self, a:data])
endfunction
let command = printf('git clone "https://github.com/junegunn/seoul256.vim.git" "%s\vimfiles\plugged yolo\seoul256.vim" 2>&1', $HOME)
let j = job_start(command, {'out_cb': 'JobCallback', 'exit_cb': 'JobCallback'})
@junegunn
junegunn / keys.go
Last active November 5, 2016 18:37
package main
import (
"fmt"
"os"
"syscall"
)
func GetBytes() []byte {
_in, _ := os.OpenFile("/dev/tty", syscall.O_RDONLY, 0)
@junegunn
junegunn / notes.sh
Last active September 1, 2024 11:40
Managing notes with fzf
#!/usr/bin/env bash
#
# Managing notes with fzf (https://github.com/junegunn/fzf)
# - CTRL-L: List note files in descending order by their modified time
# - CTRL-F: Search file contents
#
# Configuration:
# - $NOTE_DIR: Directory where note files are located
# - $NOTE_EXT: Note file extension (default: txt)