25-03-2025
This commit is contained in:
@@ -228,6 +228,10 @@ https://reposhub.com/linux/shell-applications/lincheney-fzf-tab-completion.html
|
||||
|
||||
|
||||
|
||||
### Python
|
||||
|
||||
#### Activer un venv:
|
||||
|
||||
```bash
|
||||
function activate-venv() {
|
||||
local selected_env
|
||||
@@ -239,3 +243,184 @@ function activate-venv() {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Git
|
||||
|
||||
#### Git commit history
|
||||
|
||||
```bash
|
||||
git log --oneline | fzf --preview 'git show --name-only {1}'
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### Navigateurs
|
||||
|
||||
#### Recherche dans l'historique de Firefox:
|
||||
|
||||
```bash
|
||||
cd ~/Library/Application\ Support/Firefox/Profiles/*.default-release
|
||||
sqlite3 places.sqlite "SELECT url FROM moz_places" | fzf
|
||||
```
|
||||
|
||||
#### Recherche dans les bookmarks de chrome:
|
||||
|
||||
```bash
|
||||
|
||||
b() {
|
||||
bookmarks_path=~/Library/Application\ Support/Google/Chrome/Default/Bookmarks
|
||||
|
||||
jq_script='
|
||||
def ancestors: while(. | length >= 2; del(.[-1,-2]));
|
||||
. as $in | paths(.url?) as $key | $in | getpath($key) | {name,url, path: [$key[0:-2] | ancestors as $a | $in | getpath($a) | .name?] | reverse | join("/") } | .path + "/" + .name + "\t" + .url'
|
||||
|
||||
jq -r "$jq_script" < "$bookmarks_path" \
|
||||
| sed -E $'s/(.*)\t(.*)/\\1\t\x1b[36m\\2\x1b[m/g' \
|
||||
| fzf --ansi \
|
||||
| cut -d$'\t' -f2 \
|
||||
| xargs open
|
||||
}
|
||||
```
|
||||
|
||||
#### Recherche dans l'historique de Safari:
|
||||
|
||||
```bash
|
||||
function sbh() {
|
||||
local cols sep
|
||||
cols=$(( COLUMNS / 3 ))
|
||||
sep='{::}'
|
||||
|
||||
cp -f ~/Library/Safari/History.db /tmp/h
|
||||
|
||||
sqlite3 -separator $sep /tmp/h \
|
||||
"select substr(id, 1, $cols), url
|
||||
from history_items order by visit_count_score desc" |
|
||||
awk -F $sep '{printf "%-'$cols's \x1b[36m%s\x1b[m\n", $1, $2}' |
|
||||
fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs open
|
||||
}
|
||||
|
||||
fzf-safari-browser-history()
|
||||
{
|
||||
local cols sep
|
||||
columns=$(( COLUMNS / 3 ))
|
||||
separator='{::}'
|
||||
sqlite3 -separator $separator $HOME/Library/Safari/History.db \
|
||||
"select distinct substr(title, 1, $columns), url from history_items
|
||||
inner join history_visits on history_items.id = history_visits.history_item
|
||||
order by history_visits.visit_time desc;" |
|
||||
awk -F $separator '{printf "%-'$columns's \x1b[36m%s\x1b[m\n", $1, $2}' |
|
||||
fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs open -a safari
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Terminal
|
||||
|
||||
#### Kill process:
|
||||
|
||||
```bash
|
||||
kill -9 $(ps aux | fzf | awk '{print $2}')
|
||||
```
|
||||
|
||||
#### File preview
|
||||
|
||||
```bash
|
||||
fzf --preview 'bat --style=numbers --color=always --line-range :500 {}'
|
||||
```
|
||||
|
||||
|
||||
|
||||
```bash
|
||||
fd . '/opt/homebrew' | fzf --height=90% --reverse --preview 'cat {}' --query '_log'
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Docker
|
||||
|
||||
```bash
|
||||
# Select a docker container to start and attach to
|
||||
function da() {
|
||||
local cid
|
||||
cid=$(docker ps -a | sed 1d | fzf -1 -q "$1" | awk '{print $1}')
|
||||
|
||||
[ -n "$cid" ] && docker start "$cid" && docker attach "$cid"
|
||||
}
|
||||
```
|
||||
|
||||
```bash
|
||||
# Select a running docker container to stop
|
||||
function ds() {
|
||||
local cid
|
||||
cid=$(docker ps | sed 1d | fzf -q "$1" | awk '{print $1}')
|
||||
|
||||
[ -n "$cid" ] && docker stop "$cid"
|
||||
}
|
||||
```
|
||||
|
||||
```bash
|
||||
# Select a docker container to remove
|
||||
function drm() {
|
||||
local cid
|
||||
cid=$(docker ps -a | sed 1d | fzf -q "$1" | awk '{print $1}')
|
||||
|
||||
[ -n "$cid" ] && docker rm "$cid"
|
||||
}
|
||||
# Same as above, but allows multi selection:
|
||||
function drm() {
|
||||
docker ps -a | sed 1d | fzf -q "$1" --no-sort -m --tac | awk '{ print $1 }' | xargs -r docker rm
|
||||
}
|
||||
```
|
||||
|
||||
```bash
|
||||
# Select a docker image or images to remove
|
||||
function drmi() {
|
||||
docker images | sed 1d | fzf -q "$1" --no-sort -m --tac | awk '{ print $3 }' | xargs -r docker rmi
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Homebrew Cask
|
||||
|
||||
```bash
|
||||
# Install or open the webpage for the selected application
|
||||
# using brew cask search as input source
|
||||
# and display a info quickview window for the currently marked application
|
||||
install() {
|
||||
local token
|
||||
token=$(brew search --casks "$1" | fzf-tmux --query="$1" +m --preview 'brew info {}')
|
||||
|
||||
if [ "x$token" != "x" ]
|
||||
then
|
||||
echo "(I)nstall or open the (h)omepage of $token"
|
||||
read input
|
||||
if [ $input = "i" ] || [ $input = "I" ]; then
|
||||
brew install --cask $token
|
||||
fi
|
||||
if [ $input = "h" ] || [ $input = "H" ]; then
|
||||
brew home $token
|
||||
fi
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### fzf-brew
|
||||
|
||||
```bash
|
||||
antigen bundle thirteen37/fzf-brew
|
||||
|
||||
fbi: Fuzzy brew install
|
||||
fbui: Fuzzy brew uninstall
|
||||
fci: Fuzzy cask install
|
||||
fcui: Fuzzy cask uninstall
|
||||
```
|
||||
|
||||
https://github.com/thirteen37/fzf-brew?tab=readme-ov-file
|
||||
|
||||
Reference in New Issue
Block a user