forked from enlightenment/terminology
add termio_cwd_get(), may be useful in future.
When we add multiple tabs or windows, it may be useful to get the cwd to keep context (konsole does that). SVN revision: 77664
This commit is contained in:
parent
0a4938a4f2
commit
f4c02d3e95
|
@ -2657,3 +2657,24 @@ termio_pid_get(const Evas_Object *obj)
|
|||
if (!sd) return 0;
|
||||
return termpty_pid_get(sd->pty);
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
termio_cwd_get(const Evas_Object *obj, char *buf, size_t size)
|
||||
{
|
||||
char procpath[PATH_MAX];
|
||||
Termio *sd = evas_object_smart_data_get(obj);
|
||||
pid_t pid;
|
||||
|
||||
if (!sd) return EINA_FALSE;
|
||||
|
||||
pid = termpty_pid_get(sd->pty);
|
||||
snprintf(procpath, sizeof(procpath), "/proc/%d/cwd", pid);
|
||||
if (readlink(procpath, buf, size) < 1)
|
||||
{
|
||||
ERR("Could not load working directory %s: %s",
|
||||
procpath, strerror(errno));
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
|
|
@ -19,5 +19,6 @@ int termio_scroll_get(Evas_Object *obj);
|
|||
void termio_font_size_set(Evas_Object *obj, int size);
|
||||
void termio_grid_size_set(Evas_Object *obj, int w, int h);
|
||||
pid_t termio_pid_get(const Evas_Object *obj);
|
||||
Eina_Bool termio_cwd_get(const Evas_Object *obj, char *buf, size_t size);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,16 +40,10 @@ coord_forward(int *x, int *y, int w, int h)
|
|||
static char *
|
||||
_cwd_path_get(const Evas_Object *obj, const char *relpath)
|
||||
{
|
||||
char procpath[PATH_MAX], cwdpath[PATH_MAX], tmppath[PATH_MAX];
|
||||
pid_t pid = termio_pid_get(obj);
|
||||
char cwdpath[PATH_MAX], tmppath[PATH_MAX];
|
||||
|
||||
snprintf(procpath, sizeof(procpath), "/proc/%d/cwd", pid);
|
||||
if (readlink(procpath, cwdpath, sizeof(cwdpath)) < 1)
|
||||
{
|
||||
ERR("Could not load working directory %s: %s",
|
||||
procpath, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
if (!termio_cwd_get(obj, cwdpath, sizeof(cwdpath)))
|
||||
return NULL;
|
||||
|
||||
eina_str_join(tmppath, sizeof(tmppath), '/', cwdpath, relpath);
|
||||
return strdup(tmppath);
|
||||
|
|
Loading…
Reference in New Issue