Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
O
oh-my-fish
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
oh-my-fish
Commits
81c57572
Commit
81c57572
authored
Nov 20, 2013
by
Bruno Pinto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding function to source bash scripts
parent
19700c18
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
0 deletions
+97
-0
functions/source_script.fish
functions/source_script.fish
+97
-0
No files found.
functions/source_script.fish
0 → 100644
View file @
81c57572
# Cloned from https://github.com/fish-shell/fish-shell/issues/522
function source_script --description 'Source sh/csh file'
set -l ext
set -l type
while true
switch $argv[1]
case '--sh'
set type sh
case '--csh'
set type csh
case '--bash'
set type bash
case '--ext'
set ext 1
case '*'
break
end
set -e argv[1]
end
if not test "$type"
for f in $argv
switch $f
case '*.sh'
set type bash
break
case '*.csh' '*.tcsh'
set type csh
break
end
end
end
set -l exe
set -l source
switch "$type"
case bash
set exe /bin/bash
set source .
case sh
set exe /bin/sh
set source .
case csh
set exe /bin/tcsh
set source source
case '*'
echo Unknown source type for "'$argv'"
end
if test "$ext"
eval "exec $exe -c '$source $argv; exec fish'"
else
set -l f1 (mktemp -t tmp.XXXXXXXXXX)
set -l f2 (mktemp -t tmp.XXXXXXXXXX)
eval $exe -c "'env | sort > $f1; $source $argv; env | sort > $f2'"
set -l filter "(^[^\+-]|^\+\+\+|^---|^[\+-]_|^[\+-]PIPESTATUS|^[\+-]COLUMNS)"
set -l pattern 's/[:]\{0,1\}\([^:]\+\)/"\1" /g'
set -l IFS '='
set -l diffopts --old-line-format '-=%L' --new-line-format '+=%L' --unchanged-line-format ''
diff $diffopts $f1 $f2 | grep -vE $filter | while read -l state var value
switch $state$var
case -PATH
continue
case +PATH
eval set value (echo $value | tr : ' ')
for pt in $value
contains $pt $PATH; and continue
if not test -d $pt
echo "Unable to add '$pt' to \$PATH. Check existance."
continue
end
#echo set -gx PATH $PATH $pt
set -gx PATH $PATH $pt > /dev/null
end
case '-*'
#echo unset $var
set -e $var
case '+*'
eval set -gx $var (echo $value | sed $pattern)
#echo Set $var to: (echo $value | sed $pattern)
case '*'
echo Source error! Invalid case "'$state$var'"
end
end
rm $f1 $f2 > /dev/null
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment