Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Created March 3, 2015 01:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ttscoff/4fef9fb5a945f5748c84 to your computer and use it in GitHub Desktop.
Save ttscoff/4fef9fb5a945f5748c84 to your computer and use it in GitHub Desktop.
rule and rulem bash functions coverted to Fish by Jay Berringer
#|------------------------------------------------------------------------------
#| Print a ruler in terminal window
#|
#| set -l _hr..printf assigns the result of the string interpolation to the local variable “_hr”
#| %*s waits for numeric input to define the width of the string, which in this case will be output #| as that number of spaces
#| (tput cols) is replaced with the number of columns in the current terminal as reported by tput
#| (passed to the %*s)
#| The variable is then output with sed substitution to replace the spaces with a - (default) or the #| desired character
#|------------------------------------------------------------------------------
function rule
set -l _hr (printf "%*s" (tput cols))
if test -z $argv
printf $_hr | sed -e s/ /\-/g
else
printf $_hr | sed -e s/ /\$argv/g
end
end
#|------------------------------------------------------------------------------
#| Print a ruler in terminal window with message
#|
#| set -l _hr..printf assigns the result of the string interpolation to the local variable “_hr”
#| %*s waits for numeric input to define the width of the string, which in this case will be output #| as that number of spaces
#| (tput cols) is replaced with the number of columns in the current terminal as reported by tput
#| (passed to the %*s)
#| The variable is then output with sed substitution to replace the spaces with a - (default) or the #| desired character
#|------------------------------------------------------------------------------
function rulem
set -l _hr (printf "%*s" (tput cols))
if test -z $argv[1]
echo "Usage: rulem MESSAGE [RULE_CHARACTER]"
return
else
if test (count $argv) -eq 2
printf "$_hrr33[2C$argv[1]" | sed -e s/ /\$argv[2]/g
else
printf "$_hrr33[2C$argv[1]" | sed -e s/ /\-/g
end
end
end
@BarbzYHOOL
Copy link

How to use this? (please notify me if you answer)

@krry
Copy link

krry commented Mar 13, 2019

@BarbzYHOOL, in the fish shell, you can define custom functions from the command line. If you paste the whole contents above into fish, then you can call rule or rulem. Looks like they accept arguments too. Then if you follow up with funcsave rule for example, it'll save the function to a file called rule.fish in ~/.config/fish/functions or wherever

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