Skip to content

Instantly share code, notes, and snippets.

@henri
Last active May 4, 2025 21:25
Show Gist options
  • Save henri/4f034f04b35c01e089e98350c902bda8 to your computer and use it in GitHub Desktop.
Save henri/4f034f04b35c01e089e98350c902bda8 to your computer and use it in GitHub Desktop.
fish snippits
# set random_value to be integer less than 100 # fails in BASH!
random_value=`random 1 100`
# read file in and print each line with a while loop
cat /path/to/my.file | while read -l line ; echo $line ; end
while read -l line ; echo $line ; end < /path/to/my.file
# link to fish config :
https://gist.github.com/henri/bfb800d047a910fe30fec6872c7ee63a
#!/usr/bin/env fish
#
# Script to overide the default fish_title function
#
# Copyright Henri Shustak 2024
# Released under the GNU GLP v3 or later :
# https://www.gnu.org/licenses/gpl.html
#
# This function is an overide wrapper for the fish_title.fish function
# Installation : copy into your fish functions directory :
# ~/.config/fish/functions/
#
# Start a new shell and source the script. Example usage below :
# source ~/.config/fish/functions/fish_title.fish "My New Title"
#
# Setup an alias for this using the following commands :
# alias set_title="source ~/.config/fish/functions/fish_title.fish"
# funcsave set_title
#
# Then you can use this function with this command :
# set_title "My Amazing Title" # sets the title to "My Amazing Title"
# set_title # reverts to default fish tile
#
set new_title $argv[1]
if [ "$new_title" != "" ]
# specify a specific custom fish_title function using the argument as part of this new title
function fish_title ; set -q argv[1]; or set argv ; echo "$new_title" ; end
else
# revert to default fish_title function or something else you like
# use 'functions -D fish_title' to show the path to your fish_title function
# function fish_title ;set -q argv[1]; or set argv fish ; echo (fish_prompt_pwd_dir_length=1 prompt_pwd): $argv; end
source /usr/share/fish/functions/fish_title.fish
end
# one line command to cibfugyre spb-ddg-ai functioin to start multiple DuckDuckGo AI a chats in multiple private browser tabs.
# this function requires start-private-browser to be configured : https://gist.github.com/henri/34f5452525ddc3727bb66729114ca8b4
# this function requires an alias 'start-private-browser' to be setup eg : alias --save start-private-browser="~/bin/start-private-browser.bash"
# run the following in a fish shell to configure for your shell :
function spb-ddg-ai ; set urls ( while test (count $argv) -gt 0 ; echo "https://duckduckgo.com/?t=h_&q=$argv[1]&ia=chat&bang=true" | tr " " "+" ; set --erase argv[1] ; end ) ; start-private-browser $urls ; end ; funcsave spb-ddg-ai
# usage example - lets say you want to start two chats. The first chat "tell me about cats" and have a second chat "tell me about the largest cats"
# spb-ddg-ai "tell me about cats" "tell me about the largest cats"
# starting a chat in a private browser window with DuckDuckGo AI chat, will require agreeing to DuckDuckGo usage policies with a number of clicks at the moment using the mouse.
# hopefully DuckDuck go will offer a way to include approval in the URL in the future.
# note : this command offers basic support for special characters. The only subsittion is space characters are turned into plus signs. If you are searching
# for something with odd characters then probably using this script is not a great idea.
# todo : turn this into a fisher package rather than a gist
# one line command which setups up spb-ddg as a command to search Duck Duck Go with provided search arguments in a private browser
# this function requires start-private-browser to be configured : https://gist.github.com/henri/34f5452525ddc3727bb66729114ca8b4
# this function requires an alias 'start-private-browser' to be setup eg : alias --save start-private-browser="~/bin/start-private-browser.bash"
# run the following in a fish shell to configure for your shell :
function spb-ddg ; set urls ( while test (count $argv) -gt 0 ; echo "https://duckduckgo.com/?t=h_&q=$argv[1]" | tr " " "+" ; set --erase argv[1] ; end ) ; start-private-browser $urls ; end ; funcsave spb-ddg
# usage example to open private browser and search for "search for hello world" and "search this big world" in two DuckDuck Go tabs.
# spb-ddg "search for hello world" "search this big world"
# note : this command is not complex only space characters are turned into plus signs. If you are searching
# for something with odd characters then probably using this script is not a great idea.
# todo : turn this into a fisher package rather than a gist
# one line command which setups up spb-yt as a command to search YouTube with provided search arguments in a private browser
# this function requires start-private-browser to be configured : https://gist.github.com/henri/34f5452525ddc3727bb66729114ca8b4
# this function requires an alias 'start-private-browser' to be setup eg : alias --save start-private-browser="~/bin/start-private-browser.bash"
# run the following in a fish shell to configure for your shell :
function spb-yt ; set urls ( while test (count $argv) -gt 0 ; echo "https://www.youtube.com/results?search_query=$argv[1]" | tr " " "+" ; set --erase argv[1] ; end ) ; start-private-browser $urls ; end ; funcsave spb-yt
# usage example to open private browser and search for "hello world" and "this big world" in two YouTube tabs.
# spb-yt "hello world" "this big world"
# note : this command is not complex only space characters are turned into plus signs. If you are searching
# for something with odd characters then probably using this script is not a great idea.
# todo : turn this into a fisher package rather than a gist
# from : https://www.reddit.com/user/jorbleshi_kadeshi/
# save this into : .config/fish/functions/wa.fish
# and add your APPID
function wa
set --local APPID "YOURAPPIDHERE" # Get one at https://products.wolframalpha.com/api/
echo $argv | string escape --style=url | read question_string
set --local url "https://api.wolframalpha.com/v1/result?appid="$APPID"&i="$question_string
curl -s $url
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment