mirror of
				https://github.com/mitchell/dotfiles.git
				synced 2025-11-03 21:25:26 +00:00 
			
		
		
		
	Refactor config.fish to use functions moved to functions folder
This commit is contained in:
		
							parent
							
								
									b5e93105d6
								
							
						
					
					
						commit
						47a88f93d1
					
				| 
						 | 
					@ -1,125 +1,12 @@
 | 
				
			||||||
function main
 | 
					function configure_fish
 | 
				
			||||||
  # Determine OS
 | 
					  # Determine OS
 | 
				
			||||||
  set -l uname (uname)
 | 
					  set uname (uname)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Begin profile init
 | 
					  # Begin profile init
 | 
				
			||||||
  define_variables
 | 
					  # (These functions are defined in the functions/ directory.)
 | 
				
			||||||
 | 
					  define_global_variables
 | 
				
			||||||
  import_sources $uname
 | 
					  import_sources $uname
 | 
				
			||||||
  set_aliases $uname
 | 
					  define_aliases $uname
 | 
				
			||||||
  define_functions $uname
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# define_variables defines all and exclusively globally exported variables
 | 
					configure_fish
 | 
				
			||||||
function define_variables
 | 
					 | 
				
			||||||
    set -gx AWS_SDK_LOAD_CONFIG true
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    set -gx DOTNET_ENVIRONMENT Development
 | 
					 | 
				
			||||||
    set -gx DOTNET_CLI_TELEMETRY_OPTOUT true
 | 
					 | 
				
			||||||
    set -gx DOTNET_ROOT $HOME/.asdf/installs/dotnet-core/(command -q dotnet; and dotnet --version)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    set -gx EDITOR nvim
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    set -gx FZF_CTRL_T_COMMAND 'ag --hidden --ignore .git -g ""'
 | 
					 | 
				
			||||||
    set -gx FZF_DEFAULT_COMMAND 'ag --hidden --ignore .git -g ""'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    set -gx GOPATH $HOME/code/go
 | 
					 | 
				
			||||||
    set -gx GOBIN $GOPATH/bin
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    set -gx LIBVIRT_DEFAULT_URI 'qemu:///system'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    set -gx PATH $PATH $GOBIN \
 | 
					 | 
				
			||||||
        $HOME/.local/bin \
 | 
					 | 
				
			||||||
        $HOME/.pub-cache/bin \
 | 
					 | 
				
			||||||
        $HOME/code/scripts \
 | 
					 | 
				
			||||||
        $HOME/code/flutter/bin \
 | 
					 | 
				
			||||||
        $HOME/.cargo/bin \
 | 
					 | 
				
			||||||
        $HOME/.dotnet/tools
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# import_sources loads any additional fish files in at init
 | 
					 | 
				
			||||||
function import_sources -a uname
 | 
					 | 
				
			||||||
    command -q kitty; and kitty + complete setup fish | source
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    switch $uname
 | 
					 | 
				
			||||||
        case Linux
 | 
					 | 
				
			||||||
            test -e ~/.asdf/asdf.fish; and source ~/.asdf/asdf.fish
 | 
					 | 
				
			||||||
        case Darwin
 | 
					 | 
				
			||||||
            command -q brew
 | 
					 | 
				
			||||||
            and test -e (brew --prefix asdf)/asdf.fish
 | 
					 | 
				
			||||||
            and source (brew --prefix asdf)/asdf.fish
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # The next line updates PATH for the Google Cloud SDK.
 | 
					 | 
				
			||||||
    # if test -f '/Users/m/Documents/google-cloud-sdk/path.fish.inc'; source '/Users/m/Documents/google-cloud-sdk/path.fish.inc'; end
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# set_aliases sets aliases for commonly used command
 | 
					 | 
				
			||||||
function set_aliases -a uname
 | 
					 | 
				
			||||||
    alias cp 'rsync -aP'
 | 
					 | 
				
			||||||
    alias dm 'docker-machine'
 | 
					 | 
				
			||||||
    alias v  'nvim (fzf)'
 | 
					 | 
				
			||||||
    alias vg 'vagrant'
 | 
					 | 
				
			||||||
    alias tf 'terraform'
 | 
					 | 
				
			||||||
    alias tocb 'xclip -in -selection clipboard'
 | 
					 | 
				
			||||||
    alias fromcb 'xclip -out -selection clipboard'
 | 
					 | 
				
			||||||
    alias ssh-rm-host 'ssh-keygen -f ~/.ssh/known_hosts -R'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    switch $uname
 | 
					 | 
				
			||||||
        case Linux
 | 
					 | 
				
			||||||
            alias cat      'batcat --theme ansi-dark'
 | 
					 | 
				
			||||||
            alias goland   'command goland'
 | 
					 | 
				
			||||||
            alias rider    'command rider'
 | 
					 | 
				
			||||||
            alias webstorm 'command webstorm'
 | 
					 | 
				
			||||||
        case Darwin
 | 
					 | 
				
			||||||
            alias cat      'bat --theme ansi-dark'
 | 
					 | 
				
			||||||
            alias goland   'open -a Goland'
 | 
					 | 
				
			||||||
            alias rider    'open -a Rider'
 | 
					 | 
				
			||||||
            alias webstorm 'open -a Webstorm'
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# define_functions defines a couple of small globally available functions
 | 
					 | 
				
			||||||
function define_functions -a uname
 | 
					 | 
				
			||||||
    function dm-env; eval (docker-machine env $argv); end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    function temp -a ft
 | 
					 | 
				
			||||||
        set -l file "._temp.$ft"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        touch $file
 | 
					 | 
				
			||||||
        $EDITOR $file
 | 
					 | 
				
			||||||
        rm $file
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    function _editcb -a uname ft
 | 
					 | 
				
			||||||
        set -l file "._temp.$ft"
 | 
					 | 
				
			||||||
        touch $file
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        switch $uname
 | 
					 | 
				
			||||||
            case Linux
 | 
					 | 
				
			||||||
                xclip -out -selection clipboard > $file
 | 
					 | 
				
			||||||
            case Darwin
 | 
					 | 
				
			||||||
                pbpaste > $file
 | 
					 | 
				
			||||||
        end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $EDITOR $file
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        switch $uname
 | 
					 | 
				
			||||||
            case Linux
 | 
					 | 
				
			||||||
                xclip -in -selection clipboard < $file
 | 
					 | 
				
			||||||
            case Darwin
 | 
					 | 
				
			||||||
                pbcopy < $file
 | 
					 | 
				
			||||||
        end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        rm $file
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    alias editcb "_editcb $uname"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    function back
 | 
					 | 
				
			||||||
      set log_name (string join _ $argv)
 | 
					 | 
				
			||||||
      nohup $argv > "$log_name.out" &
 | 
					 | 
				
			||||||
      echo "Log file: ./$log_name.out"
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
main
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										6
									
								
								.config/fish/functions/back.fish
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.config/fish/functions/back.fish
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					function back -d 'A shortcut for backgrounding a command using nohup and named log file'
 | 
				
			||||||
 | 
					  set log_name (string join _ $argv)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  echo "log file: $log_name.out"
 | 
				
			||||||
 | 
					  nohup $argv > "$log_name.out" &
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										24
									
								
								.config/fish/functions/define_aliases.fish
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								.config/fish/functions/define_aliases.fish
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,24 @@
 | 
				
			||||||
 | 
					function define_aliases -a uname -d 'Defines aliases for commonly used commands'
 | 
				
			||||||
 | 
					    alias cp 'rsync -aP'
 | 
				
			||||||
 | 
					    alias dm 'docker-machine'
 | 
				
			||||||
 | 
					    alias v  'nvim (fzf)'
 | 
				
			||||||
 | 
					    alias vg 'vagrant'
 | 
				
			||||||
 | 
					    alias tf 'terraform'
 | 
				
			||||||
 | 
					    alias tocb 'xclip -in -selection clipboard'
 | 
				
			||||||
 | 
					    alias fromcb 'xclip -out -selection clipboard'
 | 
				
			||||||
 | 
					    alias ssh-rm-host 'ssh-keygen -f ~/.ssh/known_hosts -R'
 | 
				
			||||||
 | 
					    alias wiki 'nvim +VimwikiIndex; and exit'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    switch "$uname"
 | 
				
			||||||
 | 
					        case 'Linux'
 | 
				
			||||||
 | 
					            alias cat      'batcat --theme ansi-dark'
 | 
				
			||||||
 | 
					            alias goland   'command goland'
 | 
				
			||||||
 | 
					            alias rider    'command rider'
 | 
				
			||||||
 | 
					            alias webstorm 'command webstorm'
 | 
				
			||||||
 | 
					        case 'Darwin'
 | 
				
			||||||
 | 
					            alias cat      'bat --theme ansi-dark'
 | 
				
			||||||
 | 
					            alias goland   'open -a Goland'
 | 
				
			||||||
 | 
					            alias rider    'open -a Rider'
 | 
				
			||||||
 | 
					            alias webstorm 'open -a Webstorm'
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										25
									
								
								.config/fish/functions/define_global_variables.fish
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								.config/fish/functions/define_global_variables.fish
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,25 @@
 | 
				
			||||||
 | 
					function define_global_variables -d 'Defines all and exclusively globally exported variables'
 | 
				
			||||||
 | 
					    set -gx AWS_SDK_LOAD_CONFIG true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    set -gx DOTNET_ENVIRONMENT Development
 | 
				
			||||||
 | 
					    set -gx DOTNET_CLI_TELEMETRY_OPTOUT true
 | 
				
			||||||
 | 
					    set -gx DOTNET_ROOT $HOME/.asdf/installs/dotnet-core/(command -q dotnet; and dotnet --version)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    set -gx EDITOR nvim
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    set -gx FZF_CTRL_T_COMMAND 'ag --hidden --ignore .git -g ""'
 | 
				
			||||||
 | 
					    set -gx FZF_DEFAULT_COMMAND 'ag --hidden --ignore .git -g ""'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    set -gx GOPATH $HOME/code/go
 | 
				
			||||||
 | 
					    set -gx GOBIN $GOPATH/bin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    set -gx LIBVIRT_DEFAULT_URI 'qemu:///system'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    set -gx PATH $PATH $GOBIN \
 | 
				
			||||||
 | 
					        $HOME/.local/bin \
 | 
				
			||||||
 | 
					        $HOME/.pub-cache/bin \
 | 
				
			||||||
 | 
					        $HOME/code/scripts \
 | 
				
			||||||
 | 
					        $HOME/code/flutter/bin \
 | 
				
			||||||
 | 
					        $HOME/.cargo/bin \
 | 
				
			||||||
 | 
					        $HOME/.dotnet/tools
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										3
									
								
								.config/fish/functions/dm_env.fish
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.config/fish/functions/dm_env.fish
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					function dm-env -d 'Shortcut for setting your shell env for a docker-machine'
 | 
				
			||||||
 | 
					  eval (docker-machine env $argv)
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										24
									
								
								.config/fish/functions/editcb.fish
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								.config/fish/functions/editcb.fish
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,24 @@
 | 
				
			||||||
 | 
					function editcb -a ft -d 'Opens your editor to the cliboard\'s current contents.'
 | 
				
			||||||
 | 
					  set uname (uname)
 | 
				
			||||||
 | 
					  set file "._temp.$ft"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  touch $file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  switch "$uname"
 | 
				
			||||||
 | 
					      case 'Linux'
 | 
				
			||||||
 | 
					          xclip -out -selection clipboard > $file
 | 
				
			||||||
 | 
					      case 'Darwin'
 | 
				
			||||||
 | 
					          pbpaste > $file
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $EDITOR $file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  switch "$uname"
 | 
				
			||||||
 | 
					      case 'Linux'
 | 
				
			||||||
 | 
					          xclip -in -selection clipboard < $file
 | 
				
			||||||
 | 
					      case 'Darwin'
 | 
				
			||||||
 | 
					          pbcopy < $file
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  rm $file
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										15
									
								
								.config/fish/functions/import_sources.fish
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								.config/fish/functions/import_sources.fish
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,15 @@
 | 
				
			||||||
 | 
					function import_sources -a uname -d 'Loads any additional fish files needed at init.'
 | 
				
			||||||
 | 
					    command -q kitty; and kitty + complete setup fish | source
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    switch "$uname"
 | 
				
			||||||
 | 
					        case 'Linux'
 | 
				
			||||||
 | 
					            test -e ~/.asdf/asdf.fish; and source ~/.asdf/asdf.fish
 | 
				
			||||||
 | 
					        case 'Darwin'
 | 
				
			||||||
 | 
					            command -q brew
 | 
				
			||||||
 | 
					            and test -e (brew --prefix asdf)/asdf.fish
 | 
				
			||||||
 | 
					            and source (brew --prefix asdf)/asdf.fish
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # The next line updates PATH for the Google Cloud SDK.
 | 
				
			||||||
 | 
					    # if test -f '/Users/m/Documents/google-cloud-sdk/path.fish.inc'; source '/Users/m/Documents/google-cloud-sdk/path.fish.inc'; end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										10
									
								
								.config/fish/functions/push_tasks.fish
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								.config/fish/functions/push_tasks.fish
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					function push_tasks -a token user -d 'Push tasks as a notification to your phone'
 | 
				
			||||||
 | 
					  set tasks (task +READY export | jq 'sort_by(.urgency) | reverse | map(@text "\(.description)\nLink: \(.link)") | join("\n\n")')
 | 
				
			||||||
 | 
					  set payload "{\"token\":\"$token\",\"user\":\"$user\",\"title\":\"Tasks\",\"message\":$tasks}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  curl \
 | 
				
			||||||
 | 
					    -X POST \
 | 
				
			||||||
 | 
					    -H 'Content-Type: application/json' \
 | 
				
			||||||
 | 
					    -d $payload \
 | 
				
			||||||
 | 
					    https://api.pushover.net/1/messages.json
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										8
									
								
								.config/fish/functions/temp.fish
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.config/fish/functions/temp.fish
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					# temp creates a temporary file in your editor, with the given filetype.
 | 
				
			||||||
 | 
					function temp -a ft
 | 
				
			||||||
 | 
					  set file "._temp.$ft"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  touch $file
 | 
				
			||||||
 | 
					  $EDITOR $file
 | 
				
			||||||
 | 
					  rm $file
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										6
									
								
								sync
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								sync
									
									
									
									
									
								
							| 
						 | 
					@ -23,8 +23,10 @@ rsync -aP ./.config/bspwm ~/.config/
 | 
				
			||||||
rsync -aP ./.config/sxhkd ~/.config/
 | 
					rsync -aP ./.config/sxhkd ~/.config/
 | 
				
			||||||
rsync -aP ./.config/picom ~/.config/
 | 
					rsync -aP ./.config/picom ~/.config/
 | 
				
			||||||
rsync -aP ./.gitconfig ~/
 | 
					rsync -aP ./.gitconfig ~/
 | 
				
			||||||
rsync -aP ./.tmux* ~/
 | 
					rsync -aP ./.tmux-line.conf ~/
 | 
				
			||||||
rsync -aP ./.vim* ~/
 | 
					rsync -aP ./.tmux.conf ~/
 | 
				
			||||||
 | 
					rsync -aP ./.vim ~/
 | 
				
			||||||
 | 
					rsync -aP ./.vimrc ~/
 | 
				
			||||||
rsync -aP ./.ideavimrc ~/
 | 
					rsync -aP ./.ideavimrc ~/
 | 
				
			||||||
rsync -aP ./.yabairc ~/
 | 
					rsync -aP ./.yabairc ~/
 | 
				
			||||||
rsync -aP ./.skhdrc ~/
 | 
					rsync -aP ./.skhdrc ~/
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue