return ret;
}
+/*
+ * "cd" command
+ */
+static const vshCmdInfo info_cd[] = {
+ {"help", gettext_noop("change the current directory")},
+ {"desc", gettext_noop("Change the current directory.")},
+ {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_cd[] = {
+ {"dir", VSH_OT_DATA, 0, gettext_noop("directory to switch to (default: home or else root)")},
+ {NULL, 0, 0, NULL}
+};
+
+static int
+cmdCd(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
+{
+ const char *dir;
+ int found;
+
+ if (!ctl->imode) {
+ vshError(ctl, FALSE, _("cd: command valid only in interactive mode"));
+ return -1;
+ }
+
+ dir = vshCommandOptString(cmd, "dir", &found);
+ if (!found) {
+ uid_t uid = geteuid();
+ dir = virGetUserDirectory(NULL, uid);
+ }
+ if (!dir)
+ dir = "/";
+
+ if (chdir (dir) == -1) {
+ vshError(ctl, FALSE, _("cd: %s: %s"), strerror (errno), dir);
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * "pwd" command
+ */
+static const vshCmdInfo info_pwd[] = {
+ {"help", gettext_noop("print the current directory")},
+ {"desc", gettext_noop("Print the current directory.")},
+ {NULL, NULL}
+};
+
+static int
+cmdPwd(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
+{
+ char *cwd;
+ size_t path_max;
+ int err = TRUE;
+
+ path_max = (size_t) PATH_MAX + 2;
+ cwd = vshMalloc (ctl, path_max);
+ while (cwd) {
+ err = getcwd (cwd, path_max) == NULL;
+ if (!err || errno != ERANGE)
+ break;
+
+ path_max *= 2;
+ cwd = vshRealloc (ctl, cwd, path_max);
+ }
+
+ if (err)
+ vshError(ctl, FALSE, _("pwd: cannot get current directory: %s"), strerror (errno));
+ else
+ vshPrint (ctl, _("%s\n"), cwd);
+
+ free (cwd);
+ return !err;
+}
+
/*
* "edit" command
*/
{"attach-interface", cmdAttachInterface, opts_attach_interface, info_attach_interface},
{"autostart", cmdAutostart, opts_autostart, info_autostart},
{"capabilities", cmdCapabilities, NULL, info_capabilities},
+ {"cd", cmdCd, opts_cd, info_cd},
{"connect", cmdConnect, opts_connect, info_connect},
{"console", cmdConsole, opts_console, info_console},
{"create", cmdCreate, opts_create, info_create},
{"pool-undefine", cmdPoolUndefine, opts_pool_undefine, info_pool_undefine},
{"pool-uuid", cmdPoolUuid, opts_pool_uuid, info_pool_uuid},
+ {"pwd", cmdPwd, NULL, info_pwd},
{"quit", cmdQuit, NULL, info_quit},
{"reboot", cmdReboot, opts_reboot, info_reboot},
{"restore", cmdRestore, opts_restore, info_restore},
.\" ========================================================================
.\"
.IX Title "VIRSH 1"
-.TH VIRSH 1 "2009-04-16" "libvirt-0.6.2" "Virtualization Support"
+.TH VIRSH 1 "2009-07-02" "libvirt-0.6.4" "Virtualization Support"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.RE
.RS 4
.RE
+.IP "\fBcd\fR \fIdirectory\fR optional" 4
+.IX Item "cd directory optional"
+Will change current directory to \fIdirectory\fR. The default directory
+for the \fBcd\fR command is the home directory or, if there is no \fI\s-1HOME\s0\fR
+variable in the environment, the root directory.
+.Sp
+This command is only available in interactive mode.
+.IP "\fBpwd\fR" 4
+.IX Item "pwd"
+Will print the current directory.
.IP "\fBconnect\fR \fI\s-1URI\s0\fR optional \fI\-\-readonly\fR" 4
.IX Item "connect URI optional --readonly"
(Re)\-Connect to the hypervisor. This is a build-in command after shell