Skip to main content

Use “fish_indent” to autoformat all my fish code

ID
e9dc23c
date
2023-11-26 02:16:41+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
25d9f81
message
Use "fish_indent" to autoformat all my fish code
changed files
6 files, 137 additions, 136 deletions

Changed files

config.fish (2207) → config.fish (2305)

diff --git a/config.fish b/config.fish
index 09bdc83..76cd3e8 100644
--- a/config.fish
+++ b/config.fish
@@ -13,16 +13,16 @@ set -x fish_function_path ~/repos/scripts/fish_functions $fish_function_path
 
 
 # Load macOS-specific utilities
-if [ (uname -s) = "Darwin" ]
-  # Provide a convenient alias for the front URL in both browsers
-  alias furl="safari url"
-  alias gurl="osascript -e 'tell application \"Google Chrome\" to tell front window to get URL of tab (active tab index)'"
+if [ (uname -s) = Darwin ]
+    # Provide a convenient alias for the front URL in both browsers
+    alias furl="safari url"
+    alias gurl="osascript -e 'tell application \"Google Chrome\" to tell front window to get URL of tab (active tab index)'"
 
-  # Get the URL of the frontmost GitHub page and clone it
-  function gh-clone
-      _ensure_ssh_key_loaded
-      github-clone (furl)
-  end
+    # Get the URL of the frontmost GitHub page and clone it
+    function gh-clone
+        _ensure_ssh_key_loaded
+        github-clone (furl)
+    end
 
 end
 
@@ -39,26 +39,26 @@ end
 # * Handle virtualenvs that are not located in the root of a git directory.
 
 function __auto_source_venv --on-variable PWD --description "Activate/Deactivate virtualenv on directory change"
-  status --is-command-substitution; and return
+    status --is-command-substitution; and return
 
-  # Check if we are inside a git directory
-  if git rev-parse --show-toplevel &>/dev/null
-    set gitdir (realpath (git rev-parse --show-toplevel))
-    set cwd (pwd)
-    # While we are still inside the git directory, find the closest
-    # virtualenv starting from the current directory.
-    while string match "$gitdir*" "$cwd" &>/dev/null
-      if test -e "$cwd/.venv/bin/activate.fish"
-        source "$cwd/.venv/bin/activate.fish" &>/dev/null
-        return
-      else
-        set cwd (path dirname "$cwd")
-      end
+    # Check if we are inside a git directory
+    if git rev-parse --show-toplevel &>/dev/null
+        set gitdir (realpath (git rev-parse --show-toplevel))
+        set cwd (pwd)
+        # While we are still inside the git directory, find the closest
+        # virtualenv starting from the current directory.
+        while string match "$gitdir*" "$cwd" &>/dev/null
+            if test -e "$cwd/.venv/bin/activate.fish"
+                source "$cwd/.venv/bin/activate.fish" &>/dev/null
+                return
+            else
+                set cwd (path dirname "$cwd")
+            end
+        end
     end
-  end
 
-  # If virtualenv activated but we are not in a git directory, deactivate.
-  if test -n "$VIRTUAL_ENV"
-    deactivate
-  end
+    # If virtualenv activated but we are not in a git directory, deactivate.
+    if test -n "$VIRTUAL_ENV"
+        deactivate
+    end
 end

fish_functions/fish_prompt.fish (4380) → fish_functions/fish_prompt.fish (4684)

diff --git a/fish_functions/fish_prompt.fish b/fish_functions/fish_prompt.fish
index e8dde1b..e0a5f7d 100644
--- a/fish_functions/fish_prompt.fish
+++ b/fish_functions/fish_prompt.fish
@@ -7,9 +7,9 @@
 
 
 function print_current_directory
-  set_color green
-  printf (echo -n (prompt_pwd))
-  set_color normal
+    set_color green
+    printf (echo -n (prompt_pwd))
+    set_color normal
 end
 
 
@@ -20,29 +20,29 @@ end
 # It's not worth maintaining those alternatives or running them against every
 # shell prompt.
 function print_git_information
-  which git 2>&1 >/dev/null
-  if [ $status = "0" ]
-    set branch (git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
-    if [ -n "$branch" ]
-      set_color normal
-      printf " on git:"
-
-      if test (basename "$branch") = "main"
-        set_color cyan
-      else
-        set_color purple
-      end
-
-      printf "$branch"
-
-      # Print an asterisk to indicate uncommitted changes, if there are any
-      if ! git diff-index --quiet HEAD --
-        printf "*"
-      end
-
-      set_color normal
+    which git 2>&1 >/dev/null
+    if [ $status = 0 ]
+        set branch (git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
+        if [ -n "$branch" ]
+            set_color normal
+            printf " on git:"
+
+            if test (basename "$branch") = main
+                set_color cyan
+            else
+                set_color purple
+            end
+
+            printf "$branch"
+
+            # Print an asterisk to indicate uncommitted changes, if there are any
+            if ! git diff-index --quiet HEAD --
+                printf "*"
+            end
+
+            set_color normal
+        end
     end
-  end
 end
 
 
@@ -54,32 +54,32 @@ end
 set -x VIRTUAL_ENV_DISABLE_PROMPT 1
 
 function print_venv_information
-  if [ -n "$VIRTUAL_ENV" ]
-    set_color normal
-    printf " using "
-
-    if test (basename "$VIRTUAL_ENV") = ".venv"
-      set_color cyan
-    else
-      set_color purple
+    if [ -n "$VIRTUAL_ENV" ]
+        set_color normal
+        printf " using "
+
+        if test (basename "$VIRTUAL_ENV") = ".venv"
+            set_color cyan
+        else
+            set_color purple
+        end
+
+        printf (basename "$VIRTUAL_ENV")
+        set_color normal
     end
-
-    printf (basename "$VIRTUAL_ENV")
-    set_color normal
-  end
 end
 
 
 # If I'm running over SSH, prepend the name of the remote host to
 # the context line.
 function print_ssh_information
-  if set -q SSH_CLIENT
-    printf "("
-    set_color purple
-    printf (echo -n (hostname))
-    set_color normal
-    printf ") "
-  end
+    if set -q SSH_CLIENT
+        printf "("
+        set_color purple
+        printf (echo -n (hostname))
+        set_color normal
+        printf ") "
+    end
 end
 
 
@@ -99,59 +99,59 @@ end
 
 
 function fish_prompt --description 'Write out the prompt'
-  # forget_dangerous_history_commands
-
-  # Put a newline between new prompts for cleanliness, but not on the first run.
-  #
-  # This means the first prompt of a new session is right at the top of
-  # the terminal window, not with a newline above it.
-  #
-  # If we're in an SSH session, we always insert a newline, even on the first
-  # command -- to separate from the client session.  I avoid getting the
-  # 'Last login' message with `touch ~/.hushlogin`
-  if set -q SSH_CLIENT
-    echo ''
-  else
-    if test \( -f "/tmp/$TERM_SESSION_ID" -o -f "/tmp/$XDG_SESSION_ID" \)
-      echo ''
+    # forget_dangerous_history_commands
+
+    # Put a newline between new prompts for cleanliness, but not on the first run.
+    #
+    # This means the first prompt of a new session is right at the top of
+    # the terminal window, not with a newline above it.
+    #
+    # If we're in an SSH session, we always insert a newline, even on the first
+    # command -- to separate from the client session.  I avoid getting the
+    # 'Last login' message with `touch ~/.hushlogin`
+    if set -q SSH_CLIENT
+        echo ''
+    else
+        if test \( -f "/tmp/$TERM_SESSION_ID" -o -f "/tmp/$XDG_SESSION_ID" \)
+            echo ''
+        end
+
+        touch "/tmp/$TERM_SESSION_ID" 2>/dev/null
+        touch "/tmp/$XDG_SESSION_ID" 2>/dev/null
     end
 
-    touch "/tmp/$TERM_SESSION_ID" 2>/dev/null
-    touch "/tmp/$XDG_SESSION_ID" 2>/dev/null
-  end
+    # Print some context about where I'm running this command.
+    #
+    # If I'm in my home directory, the context isn't very interesting (it's where
+    # new shells open, and it's not in Git), so skip the context line to reduce
+    # visual noise.
+    if [ (prompt_pwd) = "~" ]
+        if set -q SSH_CLIENT
+            print_ssh_information
+            echo ''
+        end
+        echo '$ '
+        return
+    end
 
-  # Print some context about where I'm running this command.
-  #
-  # If I'm in my home directory, the context isn't very interesting (it's where
-  # new shells open, and it's not in Git), so skip the context line to reduce
-  # visual noise.
-  if [ (prompt_pwd) = "~" ]
-    if set -q SSH_CLIENT
-      print_ssh_information
-      echo ''
+    print_ssh_information
+    print_current_directory
+    print_git_information
+    print_venv_information
+
+    # Print the shell prompt.
+    #
+    # I have a different prompt for when I'm running as root; admittedly this
+    # is extremely rare if I'm also using fish, but if I am I want a visual cue
+    # that this terminal is unusual.
+    #
+    # I print the prompt on a separate line to the context information so it's
+    # always in the same place: as I'm typing commands, I get the full width of
+    # the terminal to use, rather than a variable amount based on the context line.
+    set_color normal
+    if [ "$USER" = root ]
+        echo '' & echo '# '
+    else
+        echo '' & echo '$ '
     end
-    echo '$ '
-    return
-  end
-
-  print_ssh_information
-  print_current_directory
-  print_git_information
-  print_venv_information
-
-  # Print the shell prompt.
-  #
-  # I have a different prompt for when I'm running as root; admittedly this
-  # is extremely rare if I'm also using fish, but if I am I want a visual cue
-  # that this terminal is unusual.
-  #
-  # I print the prompt on a separate line to the context information so it's
-  # always in the same place: as I'm typing commands, I get the full width of
-  # the terminal to use, rather than a variable amount based on the context line.
-  set_color normal
-  if [ "$USER" = "root" ]
-    echo '' & echo '# '
-  else
-    echo '' & echo '$ '
-  end
 end

fish_functions/github-add-pr-branch.fish (1445) → fish_functions/github-add-pr-branch.fish (1444)

diff --git a/fish_functions/github-add-pr-branch.fish b/fish_functions/github-add-pr-branch.fish
index e2754e3..45bba91 100644
--- a/fish_functions/github-add-pr-branch.fish
+++ b/fish_functions/github-add-pr-branch.fish
@@ -24,7 +24,7 @@ function github-add-pr-branch
     #
     set components (string split "/" "$url")
 
-    if [ "$components[6]" != "pull" ]
+    if [ "$components[6]" != pull ]
         echo "$url is not a GitHub pull request"
         return 1
     end
@@ -38,4 +38,4 @@ function github-add-pr-branch
     set pr_branch (echo $api_resp | jq '.head.repo.full_name' | tr '"' ' ' | awk '{print $1}')
 
     git checkout (echo $api_resp | jq '.head.ref' | tr '"' ' ' | awk '{print $1}')
-end
\ No newline at end of file
+end

fish_functions/github-clone.fish (1983) → fish_functions/github-clone.fish (1984)

diff --git a/fish_functions/github-clone.fish b/fish_functions/github-clone.fish
index 22d51ac..d7a51c1 100644
--- a/fish_functions/github-clone.fish
+++ b/fish_functions/github-clone.fish
@@ -20,7 +20,7 @@ function github-clone
 
     if [ (count $components) -gt 5 ]
         # Detect if this is a pull request, and divert
-        if [ $components[6] = "pull" ]
+        if [ $components[6] = pull ]
             github-add-pr-branch "$url"
             return $status
         end
@@ -28,7 +28,8 @@ function github-clone
 
     set repo_url "git@github.com:$owner/$repo.git"
 
-    mkdir -p ~/repos; cd ~/repos
+    mkdir -p ~/repos
+    cd ~/repos
 
     if [ -d $repo ]
         # If the repo already exists, check we have the selected fork
@@ -59,6 +60,6 @@ function github-clone
         # but this way it's managed programatically and all local to the
         # repo, which I slightly prefer to a homefolder full of manually
         # managed dotfiles.)
-        echo .DS_Store >> .git/info/exclude
+        echo .DS_Store >>.git/info/exclude
     end
-end
\ No newline at end of file
+end

fish_functions/reload_fish_config.fish (63) → fish_functions/reload_fish_config.fish (65)

diff --git a/fish_functions/reload_fish_config.fish b/fish_functions/reload_fish_config.fish
index e9e4b9d..ba2a8de 100644
--- a/fish_functions/reload_fish_config.fish
+++ b/fish_functions/reload_fish_config.fish
@@ -1,3 +1,3 @@
 function reload_fish_config
-  . ~/.config/fish/config.fish
+    . ~/.config/fish/config.fish
 end

fish_functions/venv.fish (485) → fish_functions/venv.fish (498)

diff --git a/fish_functions/venv.fish b/fish_functions/venv.fish
index 9532010..138806a 100644
--- a/fish_functions/venv.fish
+++ b/fish_functions/venv.fish
@@ -7,12 +7,12 @@
 # I upgrade pip because otherwise I get warnings about it being
 # out-of-date, and that's annoying.
 function new_venv
-  python3 -m venv .venv
-  source .venv/bin/activate.fish
+    python3 -m venv .venv
+    source .venv/bin/activate.fish
 
-  python3 -m pip install --upgrade pip
+    python3 -m pip install --upgrade pip
 
-  if [ -f .git ]
-    echo .venv >> .git/info/exclude
-  end
+    if [ -f .git ]
+        echo .venv >>.git/info/exclude
+    end
 end