Skip to content

Instantly share code, notes, and snippets.

@Jakob-PB
Last active June 28, 2023 06:32
Show Gist options
  • Save Jakob-PB/33674ff3122e569d60b293c52b5d669b to your computer and use it in GitHub Desktop.
Save Jakob-PB/33674ff3122e569d60b293c52b5d669b to your computer and use it in GitHub Desktop.
My settings for the Windows Terminal and Bash in WSL (see instructions and keybinding below).
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
# Shows the remote ane branch names for the current working directory if it is a git repo
parse_git_branch() {
local git_repo_string=$(git rev-parse --symbolic-full-name --abbrev-ref @{u} 2> /dev/null)
if [ ! -z $git_repo_string ]; then
printf " ($git_repo_string)"
fi
}
if [ "$color_prompt" = yes ]; then
PS1="\n\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\e[33m\]\$(parse_git_branch)\[\e[00m\]\n$ "
# Normal Ubuntu terminal prompt
# PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;\w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls -pa --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# The *.rpm=90 parameter at the end tells ls to display any files ending in .rpm in
# the specified colour, in this case colour 90 (dark grey). This can be applied to any
# types of files (eg. you could use '*.png=35' to make jpeg files appear purple.) As many
# or as few parameters as you like can go into the LS_COLORS variable, as long as the
# parameters are separated by colons.
# Using trial and error (and a little bash script I wrote... my first one ever! :) I
# worked out all the colour codes, at least my interpretation of them -
#
#0 = default colour
#1 = bold
#4 = underlined
#5 = flashing text
#7 = reverse field
#31 = red
#32 = green
#33 = orange
#34 = blue
#35 = purple
#36 = cyan
#37 = grey
#40 = black background
#41 = red background
#42 = green background
#43 = orange background
#44 = blue background
#45 = purple background
#46 = cyan background
#47 = grey background
#90 = dark grey
#91 = light red
#92 = light green
#93 = yellow
#94 = light blue
#95 = light purple
#96 = turquoise
#100 = dark grey background
#101 = light red background
#102 = light green background
#103 = yellow background
#104 = light blue background
#105 = light purple background
#106 = turquoise background
#These can even be combined, so that a parameter like:
#di=1;4;31;42
LS_COLORS=$LS_COLORS':no=00'
LS_COLORS=$LS_COLORS':di=36;01'
LS_COLORS=$LS_COLORS':tw=36;01'
LS_COLORS=$LS_COLORS':ow=36;01'
LS_COLORS=$LS_COLORS':fi=00'
LS_COLORS=$LS_COLORS':ln=00'
LS_COLORS=$LS_COLORS':pi=00'
LS_COLORS=$LS_COLORS':so=00'
LS_COLORS=$LS_COLORS':ex=00'
LS_COLORS=$LS_COLORS':bd=00'
LS_COLORS=$LS_COLORS':cd=00'
LS_COLORS=$LS_COLORS':or=00'
LS_COLORS=$LS_COLORS':mi=00'
LS_COLORS=$LS_COLORS':*.sh=35'
LS_COLORS=$LS_COLORS':*.sh=35'
LS_COLORS=$LS_COLORS':*.exe=35'
LS_COLORS=$LS_COLORS':*.bat=35'
LS_COLORS=$LS_COLORS':*.com=35'
export LS_COLORS
# See colors on http://linux-sxs.org/housekeeping/lscolors.html
# di = directory
# fi = file
# ln = symbolic link
# pi = fifo file
# so = socket file
# bd = block (buffered) special file
# cd = character (unbuffered) special file
# or = symbolic link pointing to a non-existent file (orphan)
# mi = non-existent file pointed to by a symbolic link (visible when you type ls -l)
# ex = file which is executable (ie. has 'x' set in permissions).
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# Setup fzf
# ---------
if [[ ! "$PATH" == */home/jakob/.fzf/bin* ]]; then
export PATH="${PATH:+${PATH}:}/home/jakob/.fzf/bin"
fi
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'
export FZF_CTRL_T_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'"
export FZF_ALT_C_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'"
# Auto-completion
# ---------------
[[ $- == *i* ]] && source "/home/jakob/.fzf/shell/completion.bash" 2> /dev/null
# Key bindings
# ------------
# source "/home/jakob/.fzf/shell/key-bindings.bash"
__fzf_select__() {
# Strip out hidden files with "-path '*/\\.*' -o"
# local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | cut -b3-"}"
eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" fzf -m "$@" | while read -r item; do
printf '%q ' "$item"
done
echo
}
__fzf_select_limited__() {
# Strip out hidden files with "-path '*/\\.*' -o"
# local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -maxdepth 3 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -maxdepth 3 \\( -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | cut -b3-"}"
eval "$cmd" | sed -r 's/\.\n//g' | sed '/./,$!d' | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" fzf -m "$@" | while read -r item; do
printf '%q ' "$item"
done
echo
}
if [[ $- =~ i ]]; then
fzf-file-widget() {
local selected="$(__fzf_select__)"
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
}
fzf-file-widget-limited() {
local selected="$(__fzf_select_limited__)"
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
}
command_history() {
local line
shopt -u nocaseglob nocasematch
line=$(
HISTTIMEFORMAT= builtin history |
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS --tac --sync -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS +m" fzf |
command grep '^ *[0-9]') &&
if [[ $- =~ H ]]; then
sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line"
else
sed 's/^ *\([0-9]*\)\** *//' <<< "$line"
fi
}
# Required to refresh the prompt after fzf
bind '"\er": redraw-current-line'
bind '"\e^": history-expand-line'
# CTRL-F - Find (limited depth) - Paste the selected file path into the command line (limited search depth)
bind -x '"\C-f": "fzf-file-widget-limited"'
# ALT-F - Find (full) - Paste the selected file path into the command line (unlimited search depth)
bind -x '"\ef": "fzf-file-widget"'
# CTRL-H - Command History - Paste the selected command from history into the command line
bind '"\C-h": " \C-e\C-u\C-y\ey\C-u`command_history`\e\C-e\er\e^"'
fi
function explore() {
if [[ "$#" != 0 ]]; then
builtin cd "$@";
return
fi
while true; do
local lsd=$(ls -p | grep '/$' | sed 's;/$;;')
local dir="$(printf '%s\n' "${lsd[@]}" |
fzf --reverse --preview '
__cd_nxt="$(echo {})";
__cd_path="$(echo $(pwd)/${__cd_nxt} | sed "s;//;/;")";
echo $__cd_path;
echo;
ls -p --color=always "${__cd_path}";
')"
[[ ${#dir} != 0 ]] || return 0
builtin cd "$dir" &> /dev/null
done
}
# CTRL-R - Explore - Interactive cd with file preview
bind '"\C-r": "explore \n"'
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{4c606bda-875e-40c8-833e-189112b73af7}",
// You can add more global application settings here.
// To learn more about global settings, visit https://aka.ms/terminal-global-settings
// If enabled, selections are automatically copied to your clipboard.
"copyOnSelect": false,
// If enabled, formatted data is also copied to your clipboard
"copyFormatting": false,
"theme": "dark",
"initialCols": 90,
"initialRows": 25,
"alwaysShowTabs": true,
"showTabsInTitlebar": true,
"showTerminalTitleInTitlebar": false,
"wordDelimiters": " ./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}~?\u2502",
// A profile specifies a command to execute paired with information about how it should look and feel.
// Each one of them will appear in the 'New Tab' dropdown,
// and can be invoked from the commandline with `wt.exe -p xxx`
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
},
"list":
[
{
"name" : "Cmder",
"guid": "{4c606bda-875e-40c8-833e-189112b73af7}",
"commandline" : "cmd.exe /k \"C:\\cmder\\vendor\\init.bat\"",
"startingDirectory": "C:\\dev",
"fontFace" : "Consolas",
"fontSize": 11,
"useAcrylic": true,
"acrylicOpacity": 0.8,
"cursorShape": "filledBox",
"colorScheme": "Broadcast",
"tabTitle": "Cmder",
"padding" : "11, 0, 11, 22",
"icon": "C:\\cmder\\icons\\cmder.ico"
},
{
"name": "Ubuntu",
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": false,
"fontFace" : "Consolas",
"fontSize": 11,
"source": "Windows.Terminal.Wsl",
"startingDirectory": "C:\\dev",
"useAcrylic": true,
"acrylicOpacity": 0.8,
"background": "#300a24",
"cursorShape": "filledBox",
"colorScheme": "Broadcast",
"tabTitle": "Terminal",
"padding" : "11, 0, 11, 22",
"icon": "C:\\Users\\jakob\\OneDrive\\Pictures\\Internet\\icon-ubuntu-32.png"
},
{
"name" : "Windows PowerShell",
"acrylicOpacity": 0.8,
"background" : "#0e213a",
"closeOnExit" : true,
"colorScheme" : "BroadcastWin",
"commandline" : "powershell.exe",
"cursorColor" : "#FFFFFF",
"cursorShape": "filledBox",
"fontFace" : "Consolas",
"fontSize" : 11,
"guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
"padding" : "11, 0, 11, 11",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
},
{
"name" : "cmd",
"acrylicOpacity": 0.8,
"closeOnExit" : true,
"colorScheme" : "BroadcastWin",
"commandline" : "cmd.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "filledBox",
"fontFace" : "Consolas",
"fontSize" : 11,
"guid" : "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
"padding" : "11, 0, 11, 22",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": true,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
}
]
},
// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [
{
"name": "Afterglow",
"black": "#151515",
"red": "#ac4142",
"green": "#7e8e50",
"yellow": "#e5b567",
"blue": "#6c99bb",
"purple": "#9f4e85",
"cyan": "#7dd6cf",
"white": "#d0d0d0",
"brightBlack": "#858585",
"brightRed": "#ac4142",
"brightGreen": "#7e8e50",
"brightYellow": "#e5b567",
"brightBlue": "#6c99bb",
"brightPurple": "#9f4e85",
"brightCyan": "#7dd6cf",
"brightWhite": "#f5f5f5",
"background": "#212121",
"foreground": "#d0d0d0"
},
{
"name": "Broadcast",
"black": "#000000",
"red": "#da4939",
"green": "#519f50",
"yellow": "#ffd24a",
"blue": "#6d9cbe",
"purple": "#9f4e85",
"cyan": "#6e9cbe",
"white": "#ffffff",
"brightBlack": "#323232",
"brightRed": "#ff7b6b",
"brightGreen": "#83d182",
"brightYellow": "#ffff7c",
"brightBlue": "#9fcef0",
"brightPurple": "#9f4e85",
"brightCyan": "#a0cef0",
"brightWhite": "#ffffff",
"background": "#2b2b2b",
"foreground": "#e6e1dc"
},
{
"name": "BroadcastWin",
"black": "#000000",
"red": "#da4939",
"green": "#519f50",
"yellow": "#ffd24a",
"blue": "#6d9cbe",
"purple": "#9f4e85",
"cyan": "#6e9cbe",
"white": "#ffffff",
"brightBlack": "#949494",
"brightRed": "#ff7b6b",
"brightGreen": "#83d182",
"brightYellow": "#ffff7c",
"brightBlue": "#9fcef0",
"brightPurple": "#9f4e85",
"brightCyan": "#a0cef0",
"brightWhite": "#ffffff",
"background": "#2b2b2b",
"foreground": "#e6e1dc"
},
{
"name": "Campbell",
"background": "#0C0C0C",
"black": "#0C0C0C",
"blue": "#0037DA",
"brightBlack": "#767676",
"brightBlue": "#3B78FF",
"brightCyan": "#61D6D6",
"brightGreen": "#16C60C",
"brightPurple": "#B4009E",
"brightRed": "#E74856",
"brightWhite": "#F2F2F2",
"brightYellow": "#F9F1A5",
"cyan": "#3A96DD",
"foreground": "#F2F2F2",
"green": "#13A10E",
"purple": "#881798",
"red": "#C50F1F",
"white": "#CCCCCC",
"yellow": "#C19C00"
},
{
"name": "One Half Dark",
"background": "#282C34",
"black": "#282C34",
"blue": "#61AFEF",
"brightBlack": "#5A6374",
"brightBlue": "#61AFEF",
"brightCyan": "#56B6C2",
"brightGreen": "#98C379",
"brightPurple": "#C678DD",
"brightRed": "#E06C75",
"brightWhite": "#DCDFE4",
"brightYellow": "#E5C07B",
"cyan": "#56B6C2",
"foreground": "#DCDFE4",
"green": "#98C379",
"purple": "#C678DD",
"red": "#E06C75",
"white": "#DCDFE4",
"yellow": "#E5C07B"
},
{
"name": "One Half Light",
"background": "#FAFAFA",
"black": "#383A42",
"blue": "#0184BC",
"brightBlack": "#4F525D",
"brightBlue": "#61AFEF",
"brightCyan": "#56B5C1",
"brightGreen": "#98C379",
"brightPurple": "#C577DD",
"brightRed": "#DF6C75",
"brightWhite": "#FFFFFF",
"brightYellow": "#E4C07A",
"cyan": "#0997B3",
"foreground": "#383A42",
"green": "#50A14F",
"purple": "#A626A4",
"red": "#E45649",
"white": "#FAFAFA",
"yellow": "#C18301"
},
{
"name": "Solarized Dark",
"background": "#073642",
"black": "#073642",
"blue": "#268BD2",
"brightBlack": "#002B36",
"brightBlue": "#839496",
"brightCyan": "#93A1A1",
"brightGreen": "#586E75",
"brightPurple": "#6C71C4",
"brightRed": "#CB4B16",
"brightWhite": "#FDF6E3",
"brightYellow": "#657B83",
"cyan": "#2AA198",
"foreground": "#FDF6E3",
"green": "#859900",
"purple": "#D33682",
"red": "#D30102",
"white": "#EEE8D5",
"yellow": "#B58900"
},
{
"name": "Solarized Light",
"background": "#FDF6E3",
"black": "#073642",
"blue": "#268BD2",
"brightBlack": "#002B36",
"brightBlue": "#839496",
"brightCyan": "#93A1A1",
"brightGreen": "#586E75",
"brightPurple": "#6C71C4",
"brightRed": "#CB4B16",
"brightWhite": "#FDF6E3",
"brightYellow": "#657B83",
"cyan": "#2AA198",
"foreground": "#073642",
"green": "#859900",
"purple": "#D33682",
"red": "#D30102",
"white": "#EEE8D5",
"yellow": "#B58900"
}
],
// Add custom keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about keybindings, visit https://aka.ms/terminal-keybindings
"keybindings":
[
{ "command": "closeTab", "keys": "ctrl+w" },
{ "command": "newTab", "keys": "ctrl+t"},
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
{ "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
{ "command": "paste", "keys": "ctrl+v" },
// Press Ctrl+Shift+F to open the search box
{ "command": "find", "keys": "ctrl+shift+f" },
// Press Alt+Shift+D to open a new pane.
// - "split": "auto" makes this pane open in the direction that provides the most surface area.
// - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
// To learn more about panes, visit https://aka.ms/terminal-panes
{ "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
]
}
@Jakob-PB
Copy link
Author

Jakob-PB commented Mar 28, 2020

Note to Anyone Using This

  • For the Ubuntu terminal to work you are going to need to install the Windows Subsystem for Linux (WSL) and install a distribution of Ubuntu. This Microsoft documentation will walk you through all the steps required.
  • Keep in mind I'm hard coding the starting directory to C:\dev for the Ubuntu and Cmder terminals in profiles.json so if you don't have that directory you're going to run into problems.
  • You will need to download Cmder (downloading the mini version is fine if you already have Git installed) for the Cmder profile to work. Mine is located at C:\cmder but this might be different for you so check that profiles.json has the right path if you run into issues.
  • You won't have the Ubuntu icon by default. You can download the one I use here: ubuntu-icon-32, but you will definitely need to change the icon path in profiles.json to wherever you decide to put this icon.
  • The .bashrc file has a parse_git_branch() function which will show the remote and branch of any git project you are inside the directory of. This mimics the same kind of functionality you see in the Cmder terminal. It goes without saying that you'll need Git installed on your Ubuntu distribution for this to work properly.
    • If you really hate this and want your regular Ubuntu terminal prompt back just search for "Normal Ubuntu terminal prompt" in .bashrc and comment out the line above it and uncomment the line below it.
  • If you want to use fzf (I highly recommend this) for the Ubuntu terminal you will need to follow the installation instructions for Ubuntu. If your version of Ubuntu doesn't have fzf in the package manager (any version pre-19.04) then I recommend the git installation method. Then (assuming you have VS Code with the Remote - WSL extension installed) you can run code ~/.fzf.bash from the Ubuntu terminal to edit the file and replace it with the .fzf.bash in this gist.
  • There are some hard coded path assumptions in .fzf.bash about the location of /.fzf. You'll need to change the paths to point to wherever you installed fzf.

fzf Key Bindings (Ubuntu only)

  • Ctrl+R - Explore - Interactive cd with file preview via cat. Once you Ctrl+C out of fzf your terminal will automatically change directory to the last directory you were inside of in fzf. This is basically as close to a GUI file explorer in the command line as you're going to get.
  • Ctrl+F - Find - Paste the selected file path into the command line (limited search depth of 3 levels in the file system). Useful for when you need to write $somecommand /some/path/argument. Just type your command, press Ctrl+F and after you search for the directory or file you want and press Enter the path to it will be pasted at your cursor location.
  • Alt+F - Find (Full Depth) - This is like Find but with unlimited search depth while fzf is active. Unlike the regular Find fzf will eventually show all files under your current directory. fzf works in alphabetical directory/file order and recursively searches an entire directory before moving on to the next. So if one of the first directories to be searched has a lot of files (e.g. it has a .git folder) then you will need to wait a while to be able to search for even top level files/directories that are below it. This is the main reason that the regular Find uses a limited search depth (because typically you won't be searching for files past a couple levels deep). However, if you truly need to search through every single file and directory then this is your command.
  • Ctrl+H - Command History - Search commands from your history and paste them into the command line (works in a similar fashion to Find).

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