aboutsummaryrefslogtreecommitdiffhomepage
path: root/fish.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fish.cpp')
-rw-r--r--fish.cpp68
1 files changed, 44 insertions, 24 deletions
diff --git a/fish.cpp b/fish.cpp
index 24499c75..467ae787 100644
--- a/fish.cpp
+++ b/fish.cpp
@@ -12,7 +12,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
@@ -62,6 +62,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "history.h"
#include "path.h"
#include "input.h"
+#include "fish_version.h"
/* PATH_MAX may not exist */
#ifndef PATH_MAX
@@ -73,6 +74,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define GETOPT_STRING "+hilnvc:p:d:"
+/* If we are doing profiling, the filename to output to */
+static const char *s_profiling_output_filename = NULL;
+
static bool has_suffix(const std::string &path, const char *suffix, bool ignore_case)
{
size_t pathlen = path.size(), suffixlen = strlen(suffix);
@@ -188,9 +192,15 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0)
paths.doc = base_path + L"/share/doc/fish";
paths.bin = base_path + L"/bin";
+ /* Check only that the data and sysconf directories exist. Handle the doc directories separately */
struct stat buf;
if (0 == wstat(paths.data, &buf) && 0 == wstat(paths.sysconf, &buf))
{
+ /* The docs dir may not exist; in that case fall back to the compiled in path */
+ if (0 != wstat(paths.doc, &buf))
+ {
+ paths.doc = L"" DOCDIR;
+ }
done = true;
}
}
@@ -202,7 +212,7 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0)
/* Fall back to what got compiled in. */
paths.data = L"" DATADIR "/fish";
paths.sysconf = L"" SYSCONFDIR "/fish";
- paths.doc = L"" DATADIR "/doc/fish";
+ paths.doc = L"" DOCDIR;
paths.bin = L"" BINDIR;
done = true;
@@ -218,7 +228,9 @@ static void source_config_in_directory(const wcstring &dir)
const wcstring escaped_dir = escape_string(dir, ESCAPE_ALL);
const wcstring cmd = L"builtin source " + escaped_dir + L"/config.fish 2>/dev/null";
parser_t &parser = parser_t::principal_parser();
+ parser.set_is_within_fish_initialization(true);
parser.eval(cmd, io_chain_t(), TOP);
+ parser.set_is_within_fish_initialization(false);
}
/**
@@ -239,7 +251,6 @@ static int read_init(const struct config_paths_t &paths)
return 1;
}
-
/**
Parse the argument list, return the index of the first non-switch
arguments.
@@ -340,7 +351,8 @@ static int fish_parse_opt(int argc, char **argv, std::vector<std::string> *out_c
case 'p':
{
- profile = optarg;
+ s_profiling_output_filename = optarg;
+ g_profiling_active = true;
break;
}
@@ -349,7 +361,7 @@ static int fish_parse_opt(int argc, char **argv, std::vector<std::string> *out_c
fwprintf(stderr,
_(L"%s, version %s\n"),
PACKAGE_NAME,
- FISH_BUILD_VERSION);
+ get_fish_version());
exit_without_destructors(0);
}
@@ -365,18 +377,15 @@ static int fish_parse_opt(int argc, char **argv, std::vector<std::string> *out_c
is_login |= (strcmp(argv[0], "-fish") == 0);
- /*
- We are an interactive session if we have not been given an
- explicit command to execute, _and_ stdin is a tty.
- */
- is_interactive_session &= ! has_cmd;
- is_interactive_session &= (my_optind == argc);
- is_interactive_session &= isatty(STDIN_FILENO);
-
- /*
- We are also an interactive session if we have are forced-
- */
- is_interactive_session |= force_interactive;
+ /* We are an interactive session if we are either forced, or have not been given an explicit command to execute and stdin is a tty. */
+ if (force_interactive)
+ {
+ is_interactive_session = true;
+ }
+ else if (is_interactive_session)
+ {
+ is_interactive_session = ! has_cmd && (my_optind == argc) && isatty(STDIN_FILENO);
+ }
return my_optind;
}
@@ -389,7 +398,6 @@ int main(int argc, char **argv)
set_main_thread();
setup_fork_guards();
- save_term_foreground_process_group();
wsetlocale(LC_ALL, L"");
is_interactive_session=1;
@@ -410,6 +418,12 @@ int main(int argc, char **argv)
no_exec = 0;
}
+ /* Only save (and therefore restore) the fg process group if we are interactive. See #197, #1002 */
+ if (is_interactive_session)
+ {
+ save_term_foreground_process_group();
+ }
+
const struct config_paths_t paths = determine_config_directory_paths(argv[0]);
proc_init();
@@ -421,7 +435,7 @@ int main(int argc, char **argv)
reader_init();
history_init();
/* For setcolor to support term256 in config.fish (#1022) */
- update_fish_term256();
+ update_fish_color_support();
parser_t &parser = parser_t::principal_parser();
@@ -509,22 +523,28 @@ int main(int argc, char **argv)
}
}
- proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, getpid(), res);
+ int exit_status = res ? STATUS_UNKNOWN_COMMAND : proc_get_last_status();
+
+ proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, getpid(), exit_status);
+ restore_term_mode();
restore_term_foreground_process_group();
+
+ if (g_profiling_active)
+ {
+ parser.emit_profiling(s_profiling_output_filename);
+ }
+
history_destroy();
proc_destroy();
builtin_destroy();
reader_destroy();
- parser.destroy();
wutil_destroy();
event_destroy();
- env_destroy();
-
if (g_log_forks)
printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
- exit_without_destructors(res ? STATUS_UNKNOWN_COMMAND : proc_get_last_status());
+ exit_without_destructors(exit_status);
return EXIT_FAILURE; //above line should always exit
}