diff --git a/.gitignore b/.gitignore index 7e99e36..83f8619 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ -*.pyc \ No newline at end of file +*.pyc + +fish/fishd.* +fish/completions/fisher.fish +fish/conf.d/local.fish + diff --git a/Rakefile b/Rakefile index 1202b18..c06b3c2 100755 --- a/Rakefile +++ b/Rakefile @@ -26,7 +26,7 @@ desc "install the dot files into user's home directory" task :install do replace_all = false Dir['*'].each do |file| - next if %w[Rakefile README.markdown other bin bashrc.d].include? file + next if %w[Rakefile README.markdown other bin bashrc.d fish].include? file if File.exist?(File.join(ENV['HOME'], ".#{file.sub('.erb', '')}")) if File.identical? file, File.join(ENV['HOME'], ".#{file.sub('.erb', '')}") diff --git a/fish/conf.d/omf.fish b/fish/conf.d/omf.fish new file mode 100644 index 0000000..3e0f6d6 --- /dev/null +++ b/fish/conf.d/omf.fish @@ -0,0 +1,7 @@ +# Path to Oh My Fish install. +set -q XDG_DATA_HOME + and set -gx OMF_PATH "$XDG_DATA_HOME/omf" + or set -gx OMF_PATH "$HOME/.local/share/omf" + +# Load Oh My Fish configuration. +source $OMF_PATH/init.fish diff --git a/fish/fishfile b/fish/fishfile new file mode 100644 index 0000000..e69de29 diff --git a/fish/functions/fish_prompt.fish b/fish/functions/fish_prompt.fish new file mode 120000 index 0000000..cdbf1a8 --- /dev/null +++ b/fish/functions/fish_prompt.fish @@ -0,0 +1 @@ +/Users/jsc/.local/share/omf/themes/bobthefish/fish_prompt.fish \ No newline at end of file diff --git a/fish/functions/nvm.fish b/fish/functions/nvm.fish new file mode 100644 index 0000000..f57267c --- /dev/null +++ b/fish/functions/nvm.fish @@ -0,0 +1,100 @@ +function brigand_nvm_fish_find_matching_version --description 'Finds the version matching the semver string' + set -l brigand_nvm_fish_path ~/.nvm/versions/node + set -l target $argv[1] + set -l best_match 0 0 0 + set -l raw_target_parts (echo $target | tr '.' '\n') + + # pad target_parts to three items with 0s + set -l target_parts $raw_target_parts + while test (count $target_parts) -lt 3 + set target_parts $target_parts 0 + end + + for version_directory in $brigand_nvm_fish_path/v* + set -l source_version (echo "$version_directory" | sed 's/.*v//') + set -l source_parts (echo $source_version | tr '.' '\n') + + # Rules out any versions less than the requested version + set -l fail + for i in (seq 1 3) + set -l source_part $source_parts[$i] + set -l target_part $target_parts[$i] + + # skip the checks if the target digit isn't specified + if test (count $raw_target_parts) -lt $i + break + end + + # if they're equal, it's a match + if test $target_part -eq $source_part + continue + end + + # if we're asking for a newer version the check failed + if test $target_part -gt $source_part + set fail true + break + end + + if test $target_part -lt $source_part + set fail true + break + end + end + + if not test -z $fail; + continue + end + + if not test $source_parts[1] -lt $best_match[1] + if not test $source_parts[2] -lt $best_match[2] + if not test $source_parts[3] -lt $best_match[3] + set best_match $source_parts + end + end + end + end + + set best_match_string $best_match[1].$best_match[2].$best_match[3] + if not test $best_match_string = '0.0.0' + echo $best_match_string + end +end + +function nvm-fast + set -l brigand_nvm_fish_path ~/.nvm/versions/node + if test (count $argv[1]) -lt 1 + echo 'nvm-fast: at least one argument is required' + end + + set -l command $argv[1] + + if test $command = 'use' + set -l target_version $argv[2] + set -l matched_version (brigand_nvm_fish_find_matching_version $target_version) + + if test -z $matched_version + echo "No version installed for $target_version, run nvm install $target_version" + echo "Installed versions: " + for file in $brigand_nvm_fish_path/v* + echo ' -' $file + end + else + set -l new_path + for path_segment in $fish_user_paths + if not echo "$path_segment" | grep -q "$brigand_nvm_fish_path" + set new_path $new_path "$path_segment" + end + end + set new_path $brigand_nvm_fish_path/v$matched_version/bin $new_path + set fish_user_paths $new_path + end + else + bash -c "source ~/.nvm/nvm.sh; nvm $argv" + end +end + +function nvm + nvm-fast $argv +end +